-
Launch any linux vm (Centos, Ubuntu etc) from a iso
-
Install the cloud init package
RHEL: yum install cloud-init
Ubuntu : apt-get install cloud-init
- Configure the cloud init by adding the cloudstack datasource package
vi /etc/cloud/cloud.cfg.d/99_cloudstack.cfg
datasource_list: [ CloudStack, None ]
-
Create a template of the disk
-
Launch a vm based on the template created and pass the userdata parameter
deploy virtualmachine serviceofferingid=720d1320-06d7-4918-9f2a-ef5ba7e07bf3 templateid=0d9bf1f4-288d-4510-b2c5-8e980c51c98d zoneid=10a26e0d-2085-4b09-bd0f-c726a6bd9443 networkids=cf8fcdb8-741c-4f98-b856-adc4fd99c157 userdata=I2Nsb3VkLWNvbmZpZwpydW5jbWQ6CiAgLSBta2RpciAvcnVuL2tpcmFuCiAgLSBlY2hvIGtpcmFuIHNheXMgaGkgPj4gL3J1bi9raXJhbi9zYW1wbGUudHh0CiAgLSBbIHNoLCAteGMsICAvcm9vdC9zdXJlZWRnZV9zZXJ2ZXJfdXRpbGl0eV9pbnN0YWxsZXIuc2ggLS10b2tlbiAxNDY2Q0IxNTc3NzdCQjcyIF0=
Note: Make sure the userdata is encoded in base64 format if calling from Api , if you are passing the userdata from UI , there is no need to encode it
For example the following data is encoded
#cloud-config runcmd:
- mkdir /run/kiran
- echo kiran says hi » /run/kiran/sample.txt
- [ /root/sureedge_server_utility_installer.sh –token 1466CB157777BB72 ]
I2Nsb3VkLWNvbmZpZwpydW5jbWQ6CiAgLSBta2RpciAvcnVuL2tpcmFuCiAgLSBlY2hvIGtpcmFuIHNheXMgaGkgPj4gL3J1bi9raXJhbi9zYW1wbGUudHh0CiAgLSBbIHNoLCAteGMsICAvcm9vdC9zdXJlZWRnZV9zZXJ2ZXJfdXRpbGl0eV9pbnN0YWxsZXIuc2ggLS10b2tlbiAxNDY2Q0IxNTc3NzdCQjcyIF0=
- To trouble shoot the logs
tailf /var/log/cloud-init.log
cat /var/run/cloud-init/result.json
The runcmd is stored at
cat /var/lib/cloud/instance/scripts/runcmd
In summary, CloudInit takes the user data passed to the vm and executes the instructions at boot time
Ref:
https://www.ibm.com/docs/en/cic/1.1.2?topic=zvm-installation-configuration-cloud-init-linux-server
https://cloudinit.readthedocs.io/en/latest/topics/examples.html
https://www.digitalocean.com/community/tutorials/an-introduction-to-cloud-config-scripting https://www.digitalocean.com/community/tutorials/how-to-use-cloud-config-for-your-initial-server-setup
https://ibm.github.io/cloud-enterprise-examples/iac-conf-mgmt/user-data/ https://www.ibm.com/docs/en/cic/1.1.0?topic=solutions-failed-ssh-deployed-vm-correct-usernamepassword
https://cloudinit.readthedocs.io/en/latest/topics/datasources/cloudstack.html
https://docs.cloudstack.apache.org/en/latest/adminguide/virtual_machines.html#using-cloud-init