Docker-Ansible images for testing roles


These images have Ansible installed and are meant to be used for testing/developing roles.

Repository name in Docker Hub: yabhinav/ansible

This repository contains Dockerized Ansible, published to the public Docker Hub via automated build mechanism.

OS Configuration

These are Docker images for Ansible software, installed in a selected official Linux distributions.

Base OS Images:


  • All latest 2.x.0.0 major releases are provided over python virtual-env as ansible_2.x.0.0 source ~/.bashrc; workon ansible_2.2.0.0

  • Latest 2.x.x.0 version also provided over python virtual-env as ansible_latest source ~/.bashrc; workon ansible_latest

  • For ubuntu machines (since virtualenv is installed through PyPi) : source /usr/local/bin/; workon ansible_latest

Images and Tags:

Latest ansible stable releases are installed from PyPi

  • CentOS
    • 6: yabhinav/ansible:centos6
    • 7: yabhinav/ansible:centos7
  • Fedora
    • 25: yabhinav/ansible:fedora25
  • Ubuntu
    • 12.04: yabhinav/ansible:ubuntu12.04
    • 14.04: yabhinav/ansible:ubuntu14.04
    • 16.04: yabhinav/ansible:ubuntu16.04
  • Debian
    • 7: yabhinav/ansible:debian7
    • 8: yabhinav/ansible:debian8


docker pull yabhinav/ansible:centos6-multi
docker run --name testlab -h -td yabhinav/ansible:centos6-multi bash
docker exec testlab bash -c 'source ~/.bashrc; workon ansible_2.2.0.0; ansible --version'

Know Issues :

Ansible 2.2.1

  • The latest version of ansible, as of Feb2017 is, comes with major security fix , but also brings an unique bug with blocks, Refer issue. Use latest stable version for your tests or disable failed=0check.


  • With CentOS when ansible is installed with pip, the playbooks fail to run due to the bug ERROR! Unexpected Exception: 'module' object has no attribute 'HAVE_DECL_MPZ_POWM_SEC'
    • Refer issue, Anisble requires pycrypto2.6+
    • Fix is to pip install PyCrypto , refer here
  • With Fedora Missing /usr/lib/rpm/redhat/redhat-hardened-cc1

FQDN issue

  • With CentOS6 offical docker image docker run -h sets etc/hosts but ignores /etc/sysconfig/network.

  • centos:6 comes with preconfigured /etc/sysconfig/network and hence there will be an issue when ansible retrieves hostname. Sometimes it will be and sometimes it is localhost.localdomain.

  • To fix this yabhinav/ansible:centos6 docker image had been updated to remove the line HOSTNAME=localhost.localdomain from /etc/sysconfig/network

TTY Issue

  • The docker exec session hangs after ansible completed the playbook. The issue is due to some wait-timeout for service module in ansible and tty leaking memcached

  • To fix this upgrade docker-engine to 1.13+ and disable –tty in both exec and run option of docker

  • Also add ; (exit $?) at the end of command to exit with proper exit code

    $ sudo apt-get install --only-upgrade git docker-engine $ docker run --detach -h --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ubuntu1604-ansible > "${container_id}" $ docker exec "$(cat ${container_id})" bash -ic "source ~/.bashrc && workon ansible_${ansible_version} && ansible-playbook ${test_playbook} --syntax-check && deactivate ; (exit \$?)"

Sourcing issue in Ubuntu

  • Ubuntu comes with default dash shell, so source command is not found and also sourcing ~/.bashrc doesn’t load the virtualenvwrapper script.
  • To fix this set default shell in build as /bin/bash , this will be an env variable in Dockerfile SHELL ["/bin/bash", "-c"]
  • Also remove the line /[ -z "$PS1" ] && return/d from ~/.bashrc sed --in-place '/[ -z "$PS1" ] && return/d' $HOME/.bashrc

DebianFrontend issue

  • Setting ENV DEBIAN_FRONTEND noninteractive or ARG DEBIAN_FRONTEND=noninteractive helps installing apt-get packages in non-interactive shell. Make sure to add this if you are not going to use the image as an interactive shell.
  • Ansible playbook apt-get module execution fails with rpm post-installation /configure scripts running. In interactiove shell it works fine with this property (especially freeipa-server installation)

Jinja2 NOT Found

  • pip install Jinja2==2.2 paramik0=1.10 , as ansible versions between to have issue with jinja2=2.8.5 for Ubuntu12.04 and Debian 7. Refer issue

rpcbind installation hangs

  • when installing ipa-client on CentOS7 image rpcbind installation hangs the both ansibe playbook and docker exec commands alike, hence add it to image directly as a necessary package.



Author Information

Created by Abhinav Yalamanchili

Related Repositories



Ansible Container is a tool to build Docker images and orchestrate containers using only Ansible playbooks. ...



Ansible base Images for easy Ansible-Playbook-based Docker builds ...



Docker images for Ansible software, installed in a selected Linux distributions (Debian/Ubuntu/CentOS/Alpine). ...



Examples of building docker images with ansible ...



Docker images with Ansible and Kitchen CI, installed in Debian, Ubuntu and CentOS. ...