Public Repository

Last pushed: 3 months ago
Short Description
Ubuntu Trusty Docker Container for CI/CD testing Ansible Roles
Full Description

A Docker Container for testing Ansible Roles

Compatible with widely accepted Ansible testing practices! The basic idea is that you should be able to quickly and easily test your Ansible Role with a purpose-built Docker Container.

What's in ansible_build?

  • Ubuntu Trusty (latest)
  • The latest version of Ansible from the official PPA (historical versions available)
  • ansible-lint
  • git, gzip, unzip, jq, and wget
  • openjdk-7-jre-headless
  • python 2.7, python-dev and python-pip


You should have a tests directory in your Ansible role directory, containing:

  • A Dockerfile
  • An inventory file, consisting of the line localhost. You can stub/mock group results as well if needed.
  • A test.yml playbook file that calls your role for testing


Your Dockerfile should look something like this:

# Ansible test for YourCompany Your-Role.

FROM goguardian/ansible_build:latest
MAINTAINER YourCompany DevOps <>

LABEL Name yourcompany/your-role
LABEL Version 1.2.3


ADD . /etc/ansible/roles/yourcompany.your-role

RUN mkdir -p /tmp&& \
#   ansible-galaxy install owner.role-name&& \
    ansible-playbook -i /etc/ansible/roles/yourcompany.your-role/tests/inventory /etc/ansible/roles/yourcompany.your-role/tests/test.yml -c local --skip-tags "notest" --syntax-check&& \
    ansible-lint /etc/ansible/roles/yourcompany.your-role/tests/test.yml&& \
    ansible-playbook -i /etc/ansible/roles/yourcompany.your-role/tests/inventory /etc/ansible/roles/yourcompany.your-role/tests/test.yml -c local --skip-tags "notest"&& \
    ansible-playbook -i /etc/ansible/roles/yourcompany.your-role/tests/inventory /etc/ansible/roles/yourcompany.your-role/tests/test.yml -c local --skip-tags "notest"


Your test.yml file should look something like this:

- hosts: localhost
  become: yes

    ansible_distribution: "Ubuntu"
    druid_zookeepers: ",,"
    stack_env: "test"

    - { role: yourcompany.your-role }

Now what?

It's highly recommended that you make your role as dependency-free as possible. If you do have dependencies, it's really best if you can pull them from Ansible Galaxy. Otherwise, you'll need to shim your testing process by copying additional roles into the tests directory and using Dockerfile's ADD command to copy them to the test container.

Once you're done creating the necessary files, you can test your role by running cd your-role/tests and then running docker build .

Docker Pull Command