How to re-run and debug cloud-init manually

preview_player
Показать описание
The script only runs at first boot of the machine via cloud-init. If you execute the cloud-init command again it will not execute the script because it already did it. Testing and debugging the script can be quite intensive if you need to boot up a machine every time.

We can however fool cloud-init by letting it think the machine did a fresh first boot. We need to remove the following two files:

/var/lib/cloud/instances/$UUID/boot-finished
/var/lib/cloud/instances/$UUID/sem/config_scripts_user

Replace $UUID by your instance's UUID.

Execute the following command to run the cloud-init final module again:

cloud-init modules --mode final

The final module will execute our user_data script again. Before every new test run you need to remove the two files listed above.

Keep in mind as well that if you for example touch a file and run the script again, the file will still be there. Changes are persistent, build your code idempotent so that it handles that.

If you've by accident deleted to much cloud-init data you can re-initialize it with the following command:

cloud-init init
Рекомендации по теме
Комментарии
Автор

I appreciate this, amazing the lack of data on cloud-init there really is :) Question though, where is your user-data stored if you are wiping /var/lib/cloud/* I want to test a cloud-init mutli-part file, but cloud-init modules --mode final doesn't know about it, where should I put this mutli-part file, so that cloud-init parses it (so I can validate what it's doing). Thanks again, this is a great start..

torymblue
Автор

I would like to change OpenStack to NoCloud. what are step need to fallow

drmanojkumarjain
visit shbcf.ru