When you have developed some playbooks and roles with Ansible the side effect is that you may feel that development begins to move a bit slower as you manually take the time to verify variable permutations.
When you find yourself in this situation, it’s time to start testing. Here’s how to get started by using Docker and Ansible to automatically test your Ansible roles.
Deep Dive Note:
Base distro Docker images don’t normally come with ssh running. Nor do they have their init systems enabled. We are going to use the following dockerfiles hacked together Dockerfile(s) for centos6/7 and Ubuntu 12.04 (14.04 just works 🙂 to run ssh and the init system. Enough to ensure Ansible service module works against them and they can be sshed into
The default login is root / docker.io
This playbook brings up one host with Ubuntu 14.04 LTS, connects to the created host(s), and install a Minecraft server.
Source code available here: https://github.com/juanviz/ansible-testing-docker.git
Install Docker: https://docs.docker.com/install/
$ ansible-galaxy install yauh.java8
$ ansible-galaxy install provision_docker
$ ansible-docker juanvicente.herrera$ ansible-playbook test.yml