Showing posts from April, 2015

How to test ansible roles with docker

Ansible roles can be difficult to write tests for.  They change the state of a machine and may not be able to run on the distribution of linux that your development or CI machine runs.   Docker solves both of these problems very nicely. Here I will discuss how with an example project on github . Background Before adopting this strategy I found myself testing ansible roles on the actual machine they were being deployed to.  This is bad because: It's error prone (previous failed attempts can leave the machine your testing on in a state that is invalid). You have to write more code to rollback what ansible has done so you can test again. Not being able to run locally increases you edit, compile, debug cycle. In order to automate this for CI you need to set aside a machine/VM. How to test an ansible role Jeff Geerling has a great blog post on testing ansible roles with travis ci which was adapted from his book Ansible for DevOps .  His post shows you how to test that: