LXD (5.1), cloud_init and ubuntu-minimal images


I have a very strange problem. I’m trying to use containers from ubuntu-minimal: images with cloud init user data

I’ve created a profile for all my cloud-init things:

  cloud-init.user-data: |
    locale: C.UTF-8
    timezone: Europe/Moscow
      - [apt-get, -y, update]
      - [apt-get, -y, upgrade]
      - [apt, -y, autoremove]
      - [touch, /tmp/simos_was_here]
            - name: alex
              plain_text_passwd: 'foobarbaz'
                   expire: True
              ssp_pwauth: false
              shell: /bin/bash
              groups: admin, sudo
                      - ssh-ed25519 <SSH KEY> <SSH KEY ID>
            - name: ansctl
              shell: /bin/bash
                      - ssh-ed25519 <SSH KEY> <SSH KEY ID>
            - content: |
                    ansctl  ALL=(ALL) NOPASSWD: ALL
              path: /etc/sudoers.d/ansctl
              owner: root:root
              permissions: '0640'
description: General settings for instances
devices: {}
name: cloud_init

When I create a ubuntu-minimal 22 and assign the profile to it with

$ lxc init ubuntu-minimal:22.04 test22
$ lxc profile assign test22 default,cloud_init
$ lxc start test22

After some time I can see that the cloud-init completed sucsessfully:

$ lxc exec test22 bash
root@test22:~# ls -l /tmp
total 2
-rw-r--r-- 1 root root 0 May 31 12:24 simos_was_here

root@test22:~# id alex
uid=1000(alex) gid=1000(alex) groups=1000(alex),27(sudo),114(admin)
root@test22:~# id ansctl
uid=1001(ansctl) gid=1001(ansctl) groups=1001(ansctl)

But when I create a container with ubuntu-minimal:20.04 following exactly the same path, cloud-init gets ignored:

$ lxc init ubuntu-minimal:20.04 test20
Creating test20
$ lxc profile assign test20  default,cloud_init
Profiles default,cloud_init applied to test20
$ lxc start test20
$ lxc exec test20 bash
root@test20:~# cloud-init status
status: done
root@test20:~# ls /tmp
systemd-private-1c549f5b4368426d87cc20f20a1ce49b-systemd-hostnamed.service-dXo3vi  systemd-private-1c549f5b4368426d87cc20f20a1ce49b-systemd-resolved.service-95Ytah
systemd-private-1c549f5b4368426d87cc20f20a1ce49b-systemd-logind.service-DFDMUh     systemd-private-1c549f5b4368426d87cc20f20a1ce49b-systemd-timedated.service-X9gVpi
root@test20:~# id alex
id: ‘alex’: no such user
root@test20:~# id ansctl
id: ‘ansctl’: no such user


Am I missing something?

P.S. The same approach with the “full” 20.04/cloud image works, but the container get a lot of unnecessary stuff in it

Only the official “cloud” images have cloud-init installed. So, this works as expected

The ubuntu-minimal images are part of the “cloud” set (Ubuntu Minimal Cloud Images (RELEASED)) with cloud-init installed
Moreover, when I boot the 20.04 container I can see cloud-init doing something in the logs. It just doesn’t process my cloud-init config for some reason

You checked /var/log/cloud-init-output.log (or something like that) to check if its unhappy with anything?

No apparent unhappy logs in there. A bunch of keys being generated and this at the end:

Cloud-init v. 22.1-14-g2e17a0d6-0ubuntu1~20.04.3 running 'modules:config' at Tue, 31 May 2022 14:03:58 +0000. Up 18.30 seconds.
Cloud-init v. 22.1-14-g2e17a0d6-0ubuntu1~20.04.3 running 'modules:final' at Tue, 31 May 2022 14:04:02 +0000. Up 21.79 seconds.
Cloud-init v. 22.1-14-g2e17a0d6-0ubuntu1~20.04.3 finished at Tue, 31 May 2022 14:04:03 +0000. Datasource DataSourceNoCloud [seed=/var/lib/cloud/seed/nocloud-net][dsmode=net].  Up 22.91 seconds

P.S. Thanks for The Matrix :slight_smile:

How does the LXD cloud-config data get installed into the container instance?. I assume the lxd daemon copies the vendor and user-data into /var/lib/cloud-init.

So even on a non-cloud-init instance the files will still be there…

Maybe its possible to do a cloud-init clean and then run cloud-init manually in debug mode to check what its doing?

I would guess if our cloud-init files work on a full cloud-init image that the issue will be that cloud-init has already been run on this instance so its now doing a first boot install…

1 Like

Just init-ed 2 instances with 20.04 and 22.04
In 22.04 the /var/lib/cloud/instance/user-data.txt contains the correct data and /var/log/cloud-init-output.log contains output from the user config after the modules:final log entry

in 20.04 the /var/lib/cloud/instance/user-data.txt contains “{}” and modules:final is the last entry in cloud-init-output.log

So it seems that something is broken somewhere…

Inited the instances with

lxc init ubuntu-minimal:22.04 test22
lxc init ubuntu-minimal:20.04 test20

“ubuntu-minimal” is a simplestreams pointed at Ubuntu Minimal Cloud Images (RELEASED)

Have you tried using user.*keys rather than cloud-init.* keys, maybe the cloud init version is different.

The versions seems to be identical:

$ lxc exec test22 -- cloud-init --version
/usr/bin/cloud-init 22.1-14-g2e17a0d6-0ubuntu1~22.04.5
$ lxc exec test20 -- cloud-init --version
/usr/bin/cloud-init 22.1-14-g2e17a0d6-0ubuntu1~20.04.3

Changing to “user.userdata: |” from “cloud-init.user-data: |” in the profile didn’t do anything on the 20.04 :frowning:

Just wasted 3 hours trying with generic v22.04 images.

Finally, images:ubuntu/jammy/cloud worked for me.

1 Like