(Hello again. I haven’t blogged in a while. But since I’m growing weary of platforms such as medium. Here we go.)

I’ve recently spent too much a lot of time with Ansible. Once I got into the rhythm of playbooks, roles and maybe modules/libraries, I desperately needed a way to test my YAML. And by testing, I didn’t mean the annoying linting that Ansible ships with, but actual (integration) tests to verify everything works.


Enter Molecule (and TestInfra)

Molecule seems to be the go to in the Ansible universe. It’s an odd project — primarily because it’s so undocumented (and I don’t mean Python class docs, but human-readable examples).

One of the fun things about Molecule are drivers. Drivers allow me to use Docker, VirtualBox or a cloud service (like AWS, Azure, DO, Hetzner ;-)) to start instances that my playbook is run on (and then TestInfra runs assertions and collects the results). In the a nutshell, this is what Molecule does — think of it as test-kitchen.

Drivers and switching them

Drivers are crucial to a scenario. You can’t, or shouldn’t attempt to create a scenario and then switch it to another driver. When a scenario is initialised using a driver, it creates create.yml, destroy.yml (playbook) files. These files are highly specific to the driver and Molecule doesn’t play well when these are incorrect, or even missing.

It took me too long to figure this out. Hence, I’m leaving a note here.

Fin

I’ll promise I’ll blog more. Again. Thanks for reading!