Today I have been debugging why my Cloud-init scripts weren’t triggering on my Openstack environment.
I realised that something was wrong when I tried to use the noVNC console[1] with a password I’d set… no luck. So, next I ran a command to review the console logs[2], and saw a message (now, sadly, long gone – so I can’t even include it here!) suggesting there was an issue parsing my YAML file. Uh oh!
I’m using Ansible’s os_server module, and using templates to complete the userdata field, which in turn gets populated as cloud-init scripts…. and so clearly I had two ways to debug this – prefix my ansible playbook with a few debug commands, but then that can get messy… OR SSH into the box, and look through the logs. I knew I could SSH in, so the cloud-init had partially fired, but it just wasn’t parsing what I’d submitted. I had a quick look around, and found a post which mentioned debugging cloud-init. This mentioned that there’s a path (/var/lib/cloud/instances/$UUID/) you can mess around in, to remove some files to “fool” cloud-init into thinking it’s not been run… but, I reasoned, why not just see what’s there.
And in there, was the motherlode – user-data.txt…. bingo.
In the jinja2 template I was using to populate the userdata, I’d referenced another file, again using a template. It looks like that template needs an extra line at the end, otherwise, it all runs together.
Whew!
This does concern me a little, as I had previously been using this stanza to “simply” change the default user password to something a little less complicated:
#cloud-config
ssh_pwauth: True
chpasswd:
list: |
ubuntu:{{ default_password }}
expire: False
But now that I look at the documentation, I realise you can also specify that as a pre-hashed value (in which case, you would suffix that default_password
item above with |password_hash('sha512')
) which makes it all better again!
[1] If you run openstack --os-cloud cloud_a console url show servername
gives you a URL to visit that has an HTML5 based VNC-ish client. Note the “cloud_a” and “servername” should be replaced by your clouds.yml reference and the server name or server ID you want to connect to.
[2] Like before, openstack --os-cloud cloud_a console log show servername
gives you the output of the boot sequence (e.g. dmesg plus the normal startup commands, and finally, cloud-init). It can be useful. Equally, it’s logs… which means there’s a lot to wade through!