I’ve started testing my Ansible playbooks with a Ruby testing framework called serverspec. It is minimal but it does work. I was able to write and run a set of working tests in just a few minutes. When tools like this just work I view that as a good sign. Ansible is like that too.
Now I have two issues. The first is deciding how fine-grained to make my tests. I am inclined to test every line in my playbooks. I will experiment and see if that proves useful. The second issue is figuring out how to integrate serverspec into a continuous integration process.
My goal is to have the serverspec scripts run after each play is executed. I’m not sure yet how to integrate this with a continuous integration (CI) server like Jenkins. Ideally, once the Ansible script is checked into git, Jenkins would check it out and test it in the integration test environment. And then the playbook would move forward through the testing process as I have described in a previous post. I think serverspec will be a key part of this process.