Recently I've been working with cloud-config templates and custom Amazon Linux instances on AWS, when I ran into a very weird issue: the commands I put under the
runcmd section were not executed at the end of the Cloud-Init run. Weirder still was the fact the commands were written out to a shell script under
As it turns out, from around version 0.7.5 (ish) of Cloud-Init onwards, the execution of the commands from
runcmd is delegated to the
cloud-final stage, which doesn't seem to run by default when you boot from a custom AMI (based on Amazon Linux, though I've seen some posts stating the same happens on Red Hat and Ubuntu). [Source]
To fix this, you need to ensure
/etc/cloud/cloud.cfg has the following two lines (more items could be defined under
... cloud_config_modules: - runcmd - ...