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
    type: image
    mode: pull
    server: https://cloud-images.ubuntu.com/daily
    protocol: simplestreams
    alias: bionic
    user.user-data: |
      - path: /etc/environment
        content: |

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:



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:


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: