Environment variables in /etc/environment don't seem to be read

Hello !

I’m having a little issue here…
I’m trying to create a container with the latest ubuntu-daily and then, with cloud-init, set the content of /etc/environment so that, when it reboots, the proxy is set system-wide:

- name: ubuntu
  source:
    type: image
    mode: pull
    server: https://cloud-images.ubuntu.com/daily
    protocol: simplestreams
    alias: bionic
  config:
    user.user-data: |
      #cloud-config
      write_files:
      - path: /etc/environment
        content: |
          HTTP_PROXY=http://xxx.xx:3128
          HTTPS_PROXY=http://xxx.xx:3128
          NO_PROXY=xxx.xx,lxd,localhost,10.0.0.1
          http_proxy=http://xxx.xx:3128
          https_proxy=http://xxx.xx:3128
          no_proxy=xxx.xx,lxd,localhost,10.0.0.1

But it doesn’t work :frowning:
The envvar are not loaded when I do a “lxc exec ubuntu bash”
(They are loaded when I ssh though)
I tried to do it manually, or to copy it to a temp file before, or into a profile.d file, to no avail.
Is there something I’m doing wrong ?

Thanks again for your help :slight_smile:

Thomas

Hi!

It could be a formatting issue or something.
When you launch the container, have a look at /var/log/cloud-init-output.log to see whether there are any relevant errors.

Note also that write_files was introduced in a somewhat recent cloud-init. Therefore, perform your tests with Ubuntu 19.10 or newer to be sure it is OK. There is a chance that 18.04 is not new enough.

oh no, what I mean is that the file’s content is alright
but “lxc exec xxx bash” doesn’t seem to use the variables from /etc/environment

sorry if I didn’t make myself clear the first time :slight_smile:

Oh.

The shell you get with lxc exec mycontainer bash does not prepare an environment and therefore does not read /etc/environment. You need a login shell.

You would need to use instead, for example, the following. This is a built-in alias to LXD.

lxc shell mycontainer

It is equivalent to

lxc exec mycontainer -- su -l 

oh alright !
I thought the variables in /etc/environment were like… universal ^^’
Thanks for the tip !
And for the quick responses too :slight_smile: