What does "changes to it will not persist across an instance" actually mean in 50-cloud-init.yaml

5,028

Solution 1

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.

Solution 2

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...

Share:
5,028

Related videos on Youtube

aggieNick02
Author by

aggieNick02

Updated on September 18, 2022

Comments

  • aggieNick02
    aggieNick02 almost 2 years

    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?

    • s3v3n
      s3v3n over 5 years
      Did you find the answer? The "persist across an instance" wording puzzles me as well.
    • aggieNick02
      aggieNick02 over 5 years
      Unfortunately no. I've made my changes, got the behavior I want, and not had any problems.
  • aggieNick02
    aggieNick02 about 5 years
    Great explanation; knowing this file is one of the "cloud init" files leads to googling "cloud init" and help.ubuntu.com/community/CloudInit, for those looking for more info about the process in general. Thanks so much!