I'm using cloud-init to setup Ubuntu VMs on EC2. I've recently had need to support deployment using Ubuntu 12.04 (old LTS) images, but the old cloud-init 0.6.3 that is in Ubuntu 12.04 doesn't support the write_files
module that I need.
I'm currently hacking it using runcmd
and bash, but this is hardly the correct way to handle adding files to a system.
Any ideas for a better workaround?
I still don't have an elegant solution, but my hack using
runcmd
and Ruby (which may or may not be installed on your base image, so you may need to list it inpackages
) looks like this:This hack also works from relatively recent Amazon Linux instances which have a recent cloud-init, but for some reason have the
write_files
module disabled.The code assumes user-data is either the plain text
#cloud-config
or a gzip compression of that. If using something more complicated, such as multi-part or includes, then you may want to read the parsed data from/var/lib/cloud/instance/user-data.txt.i
, but that requires MIME parsing - which I'll leave as an exercise to the reader :-).