Public Repository

Last pushed: 2 years ago
Short Description
Images for running ansible from within a docker container.
Full Description


This a docker image for running ansible.
It was made as a convenient way to run ansible from within windows, but it can be used on any docker plataform as well.

Instead of running a service inside a detached container, you run /usr/bin/ansible or /usr/bin/ansible-playbook inside an interactive mode container, mapping your current windows directory (containing your ansible code) inside the container.


Docker, and some aliases shown bellow.

On Windows, I have only using both Docker Toolbox and Docker for Windows (with linux containers).

Handy Aliases

These allow you to use "ansible" and "ansible-playbook" nearly transparently.

Aliases for Docker on linux and Docker Toolbox on windows
alias ansible-playbook='docker run -it --rm -w /code -v \`pwd\`:/code dgmorales/ansible'
alias ansible='docker run -it --rm -w /code -v \`pwd\`:/code  --entrypoint /usr/bin/ansible dgmorales/ansible'

You can place these lines inside ~/.bash_profile (create this file if necessary), so they will always be available.

Docker for Windows aliases

Docker for Windows does not use bash shell as toolbox does, so we instead use powershell functions as aliases:

function ansible {
  docker run -it --rm -w /code -v ${pwd}:/code --entrypoint /usr/bin/ansible dgmorales/ansible $args

function ansible-playbook {
  docker run -it --rm -w /code -v ${pwd}:/code dgmorales/ansible $args

Place these at $Home\Documents\WindowsPowerShell\Profile.ps1 and they will be loaded automatically on the powershell terminal.

More details and LIMITATIONS

  • The aliases map (using -v) your current windows directory to /code inside the container, BUT...
  • That only works if your current windows directory is below c:\Users (that's a limitation of docker's volume mapping feature when using docker machine/docker toolbox).
  • /code is used as the CWD (-w) for the commands run in the container.
  • Because of this mapping, you should always run ansible from your repo's root dir.
  • The container is auto removed at the end (--rm)
  • The ansible.cfg inside the container sets the SSH known hosts file to be /code/.known_hosts
Docker Pull Command