What does "changes to it will not persist across an instance" actually mean in 50-cloud-init.yaml
In recent Ubuntu, netplan is the default way of configuring network adapters. I want a static IP on one of mine, and there are some guides on how to do that. Some point you to editing 50-cloud-init.yaml. But that file has an ominous warning:
# This file is generated from information provided by
# the datasource. Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
One answer on askubuntu references this and has the user do just so. (Note it has the renderer set to networkd.)
Which approach is right? Do they both work?
Most confusing, what does "persist across an instance" mean? The settings persist just fine across a reboot. When would I expect to lose settings in 50-cloud-init.yaml?
The "not across an instance" warning means that if you enter changes to the yaml file in an image that still has to perform it's first cloud-init run (on boot), the changes will be overwritten by cloud-init.
Cloud-init is used tot configre stuff on first boot. To that end it changes files on first (and optionally even subsequent) boots. The 50...yaml file is one of them.
Once cloud-init has run a first time on an image, it will not again run those changes.
The warning thus advices not to change the file on raw, unused system images for containers and virtual machines and the like.
By the way, a 'cloud-init clean' command would revert the cloud-init status to "never run before" and so would regeneratie the 50....yaml file also.
Changes to /etc/netplan/50-cloud-init.yaml are persistent across reboots but not if you backup an instance and restore it to a new one (even if your backup was done after a reboot).
I guess the solution described at Convert /etc/network/interfaces to netplan makes it persistent across instances but I figured out I'd have to update the MAC address on every instance anyway...
So I ended writing a small script that:
- appends my config at the end of /etc/netplan/50-cloud-init.yaml
- runs
sudo netplan apply
I just run this script once after every instance creation and that's it...