If you've added some runcmd lines to your cloud-init config, and the commands don't seem to be executing, here's a few things you should know:
runcmdonly has code to "shellify" your strings or array of strings (i.e: turns them into a shell script)runcmdwill only write a shell script into the file/var/lib/cloud/instance/scripts/runcmdruncmdis part of thecloud_config_modulesboot stage- You need to
executethat runcmd shell script using thescripts-usermodule scripts-useris part of thecloud_final_modulesboot stage
Here's an example config that WORKS: (as of v19.3)
cloud_config_modules:
- runcmd
cloud_final_modules:
- scripts-user
runcmd:
- [ touch, /tmp/myfile ]You can test this by manually running cloud-init modules --mode config; cloud-init modules --mode final.
Yes, I agree, the docs aren't very good ;)
4 years later and your gist is still helping - thank you.
What's the point of writing scripts first in one stage, only to run them later in a different one?