1

As far as I can see, cloud-init runs every time the config changes. Not just the very first time the system boots, but every time the provided configuration changes. This makes somewhat sense, as I guess it's hard to define the "first time" (the cloned VM already ran before being frozen and used as template, so it's never really the first time). However, I've—from time to time, quite rarely, but still—found that cloud-init re-runs on already provisioned system when they reboot.

Some steps, however, seem to screw up the setup when cloud-init is run on a fully configured system. For example, if it is run one more time after the initial setup and cloud-init sets some configuration to value X, but you had it manually overridden afterwards to Y and now cloud-init re-runs to set it back to X. Or, have the system recreate your SSH host keys.

I've thus found it quite useful to manually run:

sudo touch /etc/cloud/cloud-init.disabled

...after the initial setup to prevent it from ever running cloud-init again. (In cases, where cloud-init really is only used for an initial "clone & set IPs/hostname" kind of configurations.)

But is there any way to automate this? Like adding some parameter to the /etc/cloud/cloud.cfg that disabled itself after the next run?

miho
  • 192
  • 12

1 Answers1

2

Different cloud-init modules have different frequencies: once-per-instance and always. You can check attribute Module frequency for each module in the Modules documentation. For example, bootcmd runs on every boot but runcmd only on the first boot. The frequencies can be overridden in a cloud-config file modules lists - cloud_init_modules, cloud_config_modules and cloud_final_modules. Example override:

cloud_final_modules:
- [scripts-user, always]
AlexD
  • 8,179
  • 2
  • 28
  • 38