问题
I have used terraform to create a VPC in AWS with (so far) 1 EC2 instance; I want to get it to install mysql-server, using cloud-init. I have managed to upload a text file to /var/lib/cloud/scripts/per-once
, using user_data
:
admin@ip-10-0-1-194:~$ ll /var/lib/cloud/scripts/per-once
total 4
-rw-r--r-- 1 root root 42 Sep 16 10:41 install_mysql
admin@ip-10-0-1-194:~$ cat /var/lib/cloud/scripts/per-once/install_mysql
#cloud-config
packages:
- mysql-server
I can see in /var/log/cloud-init.log
that the module seems to run:
2019-09-16 10:41:44,630 - stages.py[DEBUG]: Running module scripts-per-once (<module 'cloudinit.config.cc_scripts_per_once' from '/usr/lib/python3/dist-packages/cloudinit/config/cc_scripts_per_once.py'>) with frequency once
2019-09-16 10:41:44,630 - handlers.py[DEBUG]: start: modules-final/config-scripts-per-once: running config-scripts-per-once with frequency once
2019-09-16 10:41:44,630 - util.py[DEBUG]: Writing to /var/lib/cloud/sem/config_scripts_per_once.once - wb: [420] 24 bytes
2019-09-16 10:41:44,631 - helpers.py[DEBUG]: Running config-scripts-per-once using lock (<FileLock using file '/var/lib/cloud/sem/config_scripts_per_once.once'>)
2019-09-16 10:41:44,631 - handlers.py[DEBUG]: finish: modules-final/config-scripts-per-once: SUCCESS: config-scripts-per-once ran successfully
But nothing gets installed - what am I doing wrong?
回答1:
so, to answer my own question, since I've found the solution and it might help others who are trying to figure out how to use cloud-init - it is actually extremely simple:
- The script needs to be executable
That's all! Should have thought of it myself, but it is often the lsmall details that get overlooked.
来源:https://stackoverflow.com/questions/57956914/why-is-my-cloud-init-script-not-getting-run