I want to automate creation of lxd container based on ubuntu images, with custom settings and scripts. Naturally, I tried using the cloud-init settings in lxd profiles, which worked well for ubuntu:18.04.
Unfortunately, with the newer images, ubuntu:18.10, ubuntu-daily:18.10, ubuntu-daily:19.04, cloud-init does no longer work (which can be verified, e.g., using these steps).
After some investigations, I figured that the cloud-init services are blocked by
$ systemctl list-jobs JOB UNIT TYPE STATE 122 cloud-config.service start waiting 107 snapd.autoimport.service start waiting 2 multi-user.target start waiting 121 cloud-init.target start waiting 1 graphical.target start waiting 127 cloud-final.service start waiting 86 systemd-update-utmp-runlevel.service start waiting 105 snapd.seeded.service start running $ less /lib/systemd/system/cloud-config.service [Unit] Description=Apply the settings specified in cloud-config After=network-online.target cloud-config.target After=snapd.seeded.service Wants=network-online.target cloud-config.target [Service] Type=oneshot ExecStart=/usr/bin/cloud-init modules --mode=config RemainAfterExit=yes TimeoutSec=0 # Output needs to appear in instance console output StandardOutput=journal+console [Install] WantedBy=cloud-init.target
Maybe the issue is caused by this bug, I am not sure. I use the latest version of snap (within the container) for which this bug should have been fixed:
$ snap version snap 2.38+19.04 snapd 2.38+19.04 series 16 ubuntu 19.04 kernel 4.14.98-v7+
Or may be it is because snap does not work well in unprivileged containers? Is there a workaround? I could manually remove snapd from the container, but I really like to automate this using profiles.