This is a container for testing Ansible roles. It includes the latest version of Ansible and is rebuilt regularly.
To build your own version of this container, run:
docker build -t ubuntu16-ansible .
To run a role inside the container, you need to run the container with your role mounted inside it. I mount my current role directory as /usr/share/ansible/roles/role_under_test
inside the container, but you can call it whatever you like.
docker run --privileged -d --volume="$(pwd)":/usr/share/ansible/roles/role_under_test:ro --name ansible-test ubuntu16-ansible /sbin/systemd
Once your container is running with your role mounted inside it, you can run you test playbook included inside the role. This is a simple playbook that just runs role_under_test
against localhost
.
docker exec -t ansible-test ansible-playbook ansible-playbook /usr/share/ansible/roles/role_under_test/tests/test.yml
You can attach to the running container by using docker exec
docker exec -i -t ansible-test bash
Once you are done testing, you can stop and remove the container.
docker stop ansible-test
docker rm ansible-test
You can automate the steps outlined above using this script.