Reinitializing network-config in existing container

I can do the following to configure networking in a new container:

lxc init ubuntu:18.04 test-cloud-init
lxc config set test-cloud-init user.network-config "$(cat test-ci.yml)"
lxc start

This works fine. Now I want to re-run cloud-init in the same container.

I modify test-ci.yml, use it to reset user.network-config, and use cloud-init clean to force cloud-init to run again on next boot:

lxc config set test-cloud-init user.network-config "$(cat test-ci.yml)"
lxc exec test-cloud-init cloud-init clean
lxc restart test-cloud-init

Unfortunately, the old configuration is re-applied. This is because the initial value of user.network-config was written to /var/lib/cloud/seed/nocloud-net/network-config inside the container, and it has not been updated with the new value of the user.network-config property.

If I do cloud-init clean --seed then the whole /var/lib/cloud/seed/ subtree is deleted, but it’s not recreated when the container restarts.

Is there a way to get lxd to refresh the contents of /var/lib/cloud/seed/nocloud-net/ on an existing container from the user.* properties?

1 Like

Doing cloud-init clean --seed in the container followed by:

  • lxc stop NAME
  • lxc config set NAME volatile.apply_template create
  • lxc start NAME

Should do the trick. This will cause both cloud-init to wipe its state and instruct LXD to re-run the templates that would normally only be run on the container’s first boot after creation.

3 Likes

That works - even with lxc restart rather than lxc stop and lxc start. Thank you!