I have created an amazon ec2 instance image (AMI) that I want to use when launching new instances but I don't understand where to store my cloud-config.txt file so that it gets executed during the first boot.
I saw that you can pass that file using the user data field in the aws interface when launching a new instance, but I thought it might be easier to put the file inside of the AMI, so that it can get automatically used as is, without having me to paste the cloud-config into the user data field.
I found a cloud-config.txt file on my disc (in /var/lib/cloud/instance) but looks like this file got generated by cloud init on boot, so if I put something inside it will get overwritten on next boot anyway.
I also tried adding a config file inside of the /var/lib/cloud/scripts/per-instance directory but it seems that this file does not get executed on boot.
I also tried to add a file inside of /etc/cloud/cloud.cfg.d, but when I do that I have an error in the /var/log/cloud-init.log saying that a module failed.
Here is the yaml style config file content:
#cloud-config runcmd: - cd /var - sudo mkdir www - cd www - groupadd www - [ sh, -c, "usermod -a -G www ec2-user" ] - [ sh, -c, "chown -R root:www /var/www" ] - chmod 2775 /var/www - npm install grunt-cli -g - bower install -g final_message: "The system is finally up, after $UPTIME seconds" # vim:syntax=yaml expandtab
What I was unable to find out is where to put this file so that cloud init uses it when I launch a new instance