Ansible runner for testing playbooks with docker connection.
- Set up hosts using docker-compose:
docker-compose -f tests/docker-compose.yml up -d
- Mount volumes in
thomasjpfan/ansible-docker-runner
with your playbooks and run all
docker run --rm -v $PWD:/etc/ansible/roles/role_to_test \
-v /var/run/docker.sock:/var/run/docker.sock:ro -ti \
thomasjpfan/ansible-docker-runner cli all
- Notice that
tests/playbook.yml
names the role under testing:role_to_test
.
lint
: Runs ansible-lint ontests/playbook.yml
.syntax-check
: Runs ansible-playbook --syntax-check ontests/playbook.yml
withtests/inventory
.converge
: Runs ansible-playbook ontests/playbook.yml
withtests/inventory
.idempotence
: Runs converge again and see if anthing changed.run_test
: Runs testtests/run_tests.sh
.requirements
: Runs ansible-galaxy install ontests/requirements.yml
.all
: Runslint
,syntax_check
,requirements
,converge
,idempotence
.
For local development, one can start a shell:
docker run --rm -v $PWD:/etc/ansible/roles/role_to_test \
--name runner \
-v /var/run/docker.sock:/var/run/docker.sock:ro -ti \
thomasjpfan/ansible-docker-runner /bin/sh
And run the commands prefixed with cli
, for example: cli lint
.
- Setting
ANSIBLE_PLAYBOOK_ARGS
in the env will be passed along to theansible-playbook
cli. - Any arguments after the command will be passed along to the
ansible-playbook
cli and overwritesANSIBLE_PLAYBOOK_ARGS
- Setting
INVENTORY_PATH
changes the default inventory path:tests/inventory
. - Setting
PLAYBOOK_PATH
changes the default playbook path:tests/playbook.yml
. - Setting
REQUIREMENTS_PATH
changes the default requirements path:requirements.yml
. - Settings
TEST_PATH
changes the default test shell path:tests/run_tests.sh
.