An easy way to test a cloud-config yaml?

testing
cloud
devops
openstack
cloud-config

(Bruce Becker) #1

I am working on a few virtual machine images using Packer and Ansible playbooks - using the OpenStack modules. Both of these have options to send user data to cloud-init when creating the virtual machine to contextualise and configure them.

Now, the issue is that cloud-init user data needs to be in valid YAML syntax. This is a bit of an issue when sending things that YAML "eats" - you can indeed quote these things with single or double quotes, but what happens when you need to send data that already has quotes in it for some other reason.

In my case, I wanted to do something like :

  1. Create user with specified ssh keys
  2. Send message to slack channel to say we're done.

A typical cloud-init would be

#cloud-config
users:
  - name: drillbot
    sudo: ALL=(ALL) NOPASSWD:ALL
    ssh-authorized-keys:
      - ssh-rsa <KEY GOES HERE>
runcmd:
  - curl -X POST -d <DATA JSON GOES HERE> <SLACK HOOK GOES HERE>

The issue is crafting this json message and slack hook in a way that both cURL and cloud-config are ok with.

Eventually, I got it right through some trial and error, but wow, was it painful !

So, my question is :

Is there a service or tool that will validate my YAML for cloud-config and simulate cloud-init ?
I don't want to have to go through the schpiel of creating the VMs and destroying them just to do a syntax check of my YAML !