imranansari / ansible-docker-runner

Ansible runner for testing playbooks with docker connection

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

thomasjpfan/ansible-docker-runner

Build Status

Ansible runner for testing playbooks with docker connection.

Usage

  1. Set up hosts using docker-compose:
docker-compose -f tests/docker-compose.yml up -d
  1. 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
  1. Notice that tests/playbook.yml names the role under testing: role_to_test.

Commands

  1. lint: Runs ansible-lint on tests/playbook.yml.
  2. syntax-check: Runs ansible-playbook --syntax-check on tests/playbook.yml with tests/inventory.
  3. converge: Runs ansible-playbook on tests/playbook.yml with tests/inventory.
  4. idempotence: Runs converge again and see if anthing changed.
  5. run_test: Runs test tests/run_tests.sh.
  6. requirements: Runs ansible-galaxy install on tests/requirements.yml.
  7. all: Runs lint, syntax_check, requirements, converge, idempotence.

Local Development

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.

Extra Features

  • Setting ANSIBLE_PLAYBOOK_ARGS in the env will be passed along to the ansible-playbook cli.
  • Any arguments after the command will be passed along to the ansible-playbook cli and overwrites ANSIBLE_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.

About

Ansible runner for testing playbooks with docker connection

License:MIT License


Languages

Language:Shell 78.9%Language:Makefile 16.9%Language:Python 4.2%