ansible-test
is a utility Ansible developers can use to perform tests (ex. unit, integration) against their code. If you are developing a playbook or role, this utility isn’t for you.
Ansible uses venv for Python environment containment. I have two systems I do development on and have been using the venv as prescribed by the documentation. However, one of my systems decided to forget it had certain Python packages installed. After about 45 minutes of debugging both venv and pyenv, I got frustrated and took to IRC. The developer’s recommendation was to use Docker for ansible-test
.
Understanding how this works is important. ansible-test
, at least in this use case, isn’t using Docker as the target for running a test. Instead, it is using it as the host system for running the test.
Running Docker with ansible-test
is pretty easy as long as Docker is installed. Take any (or almost any) ansible-test
command and add --docker
to the command. Ansible has a default Docker image they use if you don’t specify one. I don’t. I do however specify the version of Python to execute with --python 3.7
. In full, an integration test for a Meraki module looks like this:
ansible-test network-integration --allow-unsupported --docker --python 3.7 meraki_network
As expected, Docker downloaded the required images and was running tests in no time.