Any smart way to test and verify cloud-init config in XO?
-
Hi,
I'm trying to create a cloud-init config in XO to make it easier to spin up VMs. At the moment I add some changes to the config in the XO Settings->Cloud Config and then create up a new VM.
My question is if there is a smarter way to test and verify the config that doesn't involve creating, testing and deleting a VM every time I have made a change to the config?
Thanks in advance.
-
-
-
To verify that the cloud-init config is valid you could pop it over into a cloud-init enabled ubuntu machine as a cloud.cfg file in /etc/cloud. Running a "cloud-init init" command will have it read the file and report any errors
-
Sure, if you just want to pre-test and render configs there are a few methods. Just off the top of my head:
Verify user data in container: cloud-init query userdata # This will printout the config used to configure instance so you can see how it was rendered.
To see how cloud-init rendered your config as passed from nocloud
Validate the cloud-config:cloud-init devel schema --system --annotate
To test a config file:
Verify cloud config schema:cloud-init devel schema --config-file test.cfg
Example: cloud-init devel schema --config-file user-data.yaml
While in the instance, you can check the files in the nocloud datasource as well, and tweak them as needed till it passes the checks:
Run the following as a guide
mount /dev/xvdb /mnt cd /mnt root@Deb99990:/mnt# cloud-init schema -c user-data --annotate Valid cloud-config: user-data root@Deb99990:/mnt# cloud-init schema -c network-config --annotate Valid cloud-config: network-config
If you have errors or typos in your yaml, it will point them out, so you can address the error. Then once they pass the schema check, you can copy the config to your cloud-init configs in XO. Hope that helps.
Also if you just want to test the cloud-init config process on the same VM, you can "reboot" cloud-init with: cloud-init clean --logs --reboot and it will start fresh and re-apply the configs.
Then check the results with cloud-init status --long - or if it is still running (as in the case of a container) you can run: cloud-init status --wait till it finishes.
-
@runevn
A bit more from my 'troubleshooting notes' I gathered back when I was prototyping a lot of very complex configurations and worked with Chad Smith:Test user-data rendering: cloud-init query --format "$(sudo cloud-init query userdata)"
Test jinja template rendering: cloud-init query --format="$( cat test.cfg )" # test.cfg would be the test cloud-config.cfg file to renderTest jinja template detailed: cloud-init devel render test.cfg -d
Query metadata: cloud-init query -f {{v1.distro}}========= Debug user-data rendering =============
cloud-init devel render /var/lib/cloud/instance/user-data.txt -dCheck actual seed file from provider
cloud-init devel render /var/lib/cloud/seed/nocloud-net/user-data -d
On a system where cloud-config wasn't honored, run: sudo cloud-init query --system # or you can add
--annotate
which will annotate the specific lines where an error is in the #cloud-config YAML
per Chad Smith;All cloud-init instance data /var/lib/cloud/instance/
Userdata /var/lib/cloud/instance/user-data.txt
Datasource /var/lib/cloud/instance/datasource
metadata /run/cloud-init/instance-data.json
Seed files from provider/hypervisor: /var/lib/cloud/seed/nocloud-netFor anyone doing a deep dive into troubleshooting cloud-init configuration rendering.