Testing Ansible in Azure - Wed, Jun 30, 2021
Testing with Molecule
Download all the Source and Templates here
Most of my colleagues will attest that I have a strong passion for ensuring the reliability of the code that I write. I have a borderline obsession with testing! Whenever I can, I look to increase the test coverage.
I recently contributed to a solution that required the use of multiple Virtual Machines (VMs) to build custom images of different Operating Systems (OS). This solution was making heavy use of Infrastructure as Code (IaC), like many other projects out there. As the IaC grew, I started to see the need for automated testing of the installation and setup code written. The project used Ansible as the provisioner (with some help from Packer). My idea was that we should find a way to test each step or, at the very least, the final output of the Ansible playbooks. The search for a solution led me to find Molecule. Taken from the Molecule site, Molecule provides support for testing with multiple instances, operating systems and distributions, virtualization providers, test frameworks, and testing scenarios.
Molecule provided us with a great way to test our various Ansible roles and playbooks reliably and autonomously. In this blog post, I have provided links to the sections of my GitHub repository that includes the workflow walkthrough and templates that we used to test our Ansible Playbooks on deployable Azure Cloud components.