Reputation: 591
I am trying to automate provisioning of linux machines (rhel8) using cloudinit.
For this purpose I created an ISO with the following content:
[root@]# tree rhel82test1/
rhel82test1/
├── meta-data
├── network-config
├── scripts
│ └── per-instance
│ └── demo.sh
└── user-data
2 directories, 4 files
This iso gets added to the VM during virt-install.
The user-data, meta-data and network-config get applied as expected. However I expected the demo.sh script to be executed as well. I see in the logs that config-scripts-per-instance gets run, but the script is not executed. It is als not present in /var/lib/cloud/instance/scripts
What am I doing wrong here. Is this not the correct way to have scripts executed?
Upvotes: 0
Views: 660
Reputation: 4226
This caused me a lot of grief, and it feels intentional, something to do with competing clown-providers, but that could be the pain talking. I guess they really could be dumber than a bag of hammers. I mean, cloud-init isn't exactly the most elegant project out there.
Anyway, for my cloud-init 24.1.3 on Alpine 3.20.3, putting the script in /var/lib/cloud/scripts/per-instance/
using write_files
(in user-data) does the trick, like this:
write_files:
- path: /var/lib/cloud/scripts/per-instance/too_dumb_to_breathe
owner: "root:root"
permissions: "0755"
defer: false
content: |
#!/bin/sh
echo "hello..." >/dev/tty0
set -e
mount $(blkid | grep 'LABEL="cidata"' | cut -d: -f1) /mnt
echo "looks like cidata is accessible:" >/dev/tty0
ls -R /mnt >/dev/tty0
The write apparently happens before that directory is scanned for scripts to run, so it happens to work here, but it doesn't seem like intentional behaviour. I can't find anything in the docs to say so, anyway.
Upvotes: 0