/etc/netplan/50-cloud-init.yaml spontaneously created when container is stopped, renamed, and then started

Bare metal context: Ubuntu 22.02.2 running latest/stable snap lxd.
The default profile networking is set to NIC-bound br0 bridge with no local bridge enabled.

lxc init ubuntu:22.04 digital-archives

After spinning up this container, I created a /etc/netplan/10-lxc.yaml file configured with a static IP address and moved 50-cloud-init.yaml to 50-cloud-init.yaml-ORIG so it wouldn’t execute and ran
netplan apply

However, see below:

archives@www2:~$ lxc list
+------------------+---------+---------------------+------+-----------+-----------+
|       NAME       |  STATE  |        IPV4         | IPV6 |   TYPE    | SNAPSHOTS |
+------------------+---------+---------------------+------+-----------+-----------+
| digital-archives | RUNNING | 172.18.90.42 (eth0) |      | CONTAINER | 0         |
+------------------+---------+---------------------+------+-----------+-----------+
archives@www2:~$ lxc stop digital-archives
archives@www2:~$ lxc list
+------------------+---------+------+------+-----------+-----------+
|       NAME       |  STATE  | IPV4 | IPV6 |   TYPE    | SNAPSHOTS |
+------------------+---------+------+------+-----------+-----------+
| digital-archives | STOPPED |      |      | CONTAINER | 0         |
+------------------+---------+------+------+-----------+-----------+
archives@www2:~$ lxc move digital-archives digitalarchives
archives@www2:~$ lxc list
+-----------------+---------+------+------+-----------+-----------+
|      NAME       |  STATE  | IPV4 | IPV6 |   TYPE    | SNAPSHOTS |
+-----------------+---------+------+------+-----------+-----------+
| digitalarchives | STOPPED |      |      | CONTAINER | 0         |
+-----------------+---------+------+------+-----------+-----------+
archives@www2:~$ lxc start digitalarchives
archives@www2:~$ lxc list
+-----------------+---------+----------------------+------+-----------+-----------+
|      NAME       |  STATE  |         IPV4         | IPV6 |   TYPE    | SNAPSHOTS |
+-----------------+---------+----------------------+------+-----------+-----------+
| digitalarchives | RUNNING | 172.18.90.42 (eth0)  |      | CONTAINER | 0         |
|                 |         | 172.18.90.227 (eth0) |      |           |           |
+-----------------+---------+----------------------+------+-----------+-----------+

On further examination, the 50-cloud-init.yaml netplan was magically recreated:

root@digital-archives:~# ls /etc/netplan
10-lxc.yaml  50-cloud-init.yaml  50-cloud-init.yaml-ORIG

Any idea why this happened?

I changed the name of the container back to the original name, removed /etc/netplan/50-cloud-init.yaml and now the behavior doesn’t repeat:

archives@www2:~$ lxc list
+------------------+---------+---------------------+------+-----------+-----------+
|       NAME       |  STATE  |        IPV4         | IPV6 |   TYPE    | SNAPSHOTS |
+------------------+---------+---------------------+------+-----------+-----------+
| digital-archives | RUNNING | 172.18.90.42 (eth0) |      | CONTAINER | 0         |
+------------------+---------+---------------------+------+-----------+-----------+
archives@www2:~$ lxc stop digital-archives
archives@www2:~$ lxc start digital-archives
archives@www2:~$ lxc list
+------------------+---------+---------------------+------+-----------+-----------+
|       NAME       |  STATE  |        IPV4         | IPV6 |   TYPE    | SNAPSHOTS |
+------------------+---------+---------------------+------+-----------+-----------+
| digital-archives | RUNNING | 172.18.90.42 (eth0) |      | CONTAINER | 0         |
+------------------+---------+---------------------+------+-----------+-----------+

Just a little bit of additional testing shows that the creation of /etc/netplan/50-cloud-init.yaml is triggered by changing the name of the container. Repeating my previous steps:

archives@www2:~$ lxc list
+------------------+---------+---------------------+------+-----------+-----------+
|       NAME       |  STATE  |        IPV4         | IPV6 |   TYPE    | SNAPSHOTS |
+------------------+---------+---------------------+------+-----------+-----------+
| digital-archives | RUNNING | 172.18.90.42 (eth0) |      | CONTAINER | 0         |
+------------------+---------+---------------------+------+-----------+-----------+
archives@www2:~$ lxc stop digital-archives
archives@www2:~$ lxc move digital-archives digitalarchives
archives@www2:~$ lxc list
+-----------------+---------+------+------+-----------+-----------+
|      NAME       |  STATE  | IPV4 | IPV6 |   TYPE    | SNAPSHOTS |
+-----------------+---------+------+------+-----------+-----------+
| digitalarchives | STOPPED |      |      | CONTAINER | 0         |
+-----------------+---------+------+------+-----------+-----------+
archives@www2:~$ lxc start digitalarchives
archives@www2:~$ lxc list
+-----------------+---------+----------------------+------+-----------+-----------+
|      NAME       |  STATE  |         IPV4         | IPV6 |   TYPE    | SNAPSHOTS |
+-----------------+---------+----------------------+------+-----------+-----------+
| digitalarchives | RUNNING | 172.18.90.42 (eth0)  |      | CONTAINER | 0         |
|                 |         | 172.18.90.227 (eth0) |      |           |           |
+-----------------+---------+----------------------+------+-----------+-----------+

I’m going to call this a bug rather than a feature. :slightly_smiling_face:

The LXD team do not produce the images from ubuntu: remote, so ubuntu:22.04 is one of the official Ubuntu images.

Does it occur using the images:ubuntu/22.04 or images:ubuntu/22.04/cloud images?

I’ve only ever used the images:ubuntu/22.04 images, so it’s happening with those images. This isn’t a huge issue since the names of containers rarely change, I suspect, but I don’t understand how this would be happening, which is what bothers me.

I’ve confirmed this behaviour, and its happening because LXD regenerates the volatile.cloud-init.instance-id config key on rename. This then triggers cloud-init to regenerate its config on next start.

See https://linuxcontainers.org/lxd/docs/master/reference/instance_options/#volatile-internal-data

And https://github.com/lxc/lxd/issues/9814

Yep. I just came to this post to confirm that it’s cloud-init causing this. I suppose I should have guessed this from the the name 50-cloud-init.yaml. I’ll mark your answer as the solution, but for the convenience of someone else who might come along, these are the steps to get rid of cloud-init:

$ lxc exec my_container bash
# dpkg-reconfigure cloud-init
  --- remove everything except none
# apt purge cloud-init
# apt auto-remove
# rm -rf /etc/cloud/ && sudo rm -rf /var/lib/cloud/

After this you can change container names without suffering the re-emergence of zombie 50-cloud-init.yaml. I need to remember to do this automatically every time I launch an Ubuntu container.

1 Like

Theres also images:ubuntu/jammy etc that don’t contain cloud-init

1 Like