Hi folks,
since it’s not documented anywhere, (https://www.digitalocean.com/community/tutorials/an-introduction-to-cloud-config-scripting / http://cloudinit.readthedocs.io/en/latest/topics/modules.html) and I got to find out the hard way that write_files
runs after runcmd
, i was wondering if it’s possible to change the order in which cloud-init modules are executed?
The reasoning is that i will frequently need to place a bunch of files in place (config files, keys, etc) before being able to successfully run a command.
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hi @me554b5ddf77bd4849acbdb294
I’ve just tried to spin up two droplets (FreeBSD and Ubuntu) with this:
And this file
/root/test.txt
looks like this after droplet creation on Ubuntu (correct):But on FreeBSD it looks like this (wrong):
That’s because
write-files
is not included in stagecloud_init_modules
on FreeBSD.Can you create a ticket to Support via the control panel, where you link to this thread. It seems like a bug, but I’m not sure if the FreeBSD cloud-init is just limited a bit.
FreeBSD
/usr/local/etc/cloud/cloud.cfg
Ubuntu
/etc/cloud/cloud.cfg
Ran into this as well on ubuntu 18.04 :(
On other clouds (AWS) this works as expected (write_files before runcmd) for standard ubuntu 18.04
You can do something like this:
This should work regardless of whether
write_files
orruncmd
happens first, but note it will cause theruncmd
block to exit before the command actually finishes.For me this is fine,
my-script.sh
also needs to run after cloud-init finishes all of its other processing, which is achieved as follows: