Skip to content
Docker Image of Ansible for executing ansible-playbook command against an externally mounted set of Ansible playbooks
Branch: master
Clone or download
Pull request Compare This branch is 4 commits ahead of walokra:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Dockerfile
README.md
ps_profile.txt

README.md

Ansible Playbook Docker Image

Docker Image of Ansible for executing ansible-playbook command against an externally mounted set of Ansible playbooks. Based on philm/ansible_playbook

Build

docker build -t ansible-docker .

Test

$ docker run --name ansible-docker --rm ansible-playbook --version

ansible-playbook 2.5.0
  config file = None
  configured module search path = [u'/ansible/library']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 2.7.15 (default, Aug 16 2018, 14:17:09) [GCC 6.4.0]

Running Ansible Playbook

docker run --rm -it -v PATH_TO_LOCAL_PLAYBOOKS_DIR:/ansible/playbooks ansible-docker PLAYBOOK_FILE

For example, assuming your project's structure follows best practices, the command to run ansible-playbook from the top-level directory would look like:

docker run --rm -it -v $(pwd):/ansible/playbooks ansible-docker site.yml

Ansible playbook variables can simply be added after the playbook name.

SSH Keys

If Ansible is interacting with external machines, you'll need to mount an SSH key pair for the duration of the play: FYI: this is for Linux. I have no idea how to get this to work on Windows.

docker run --rm -it \
    -v ~/.ssh/id_rsa:/root/.ssh/id_rsa \
    -v ~/.ssh/id_rsa.pub:/root/.ssh/id_rsa.pub \
    -v $(pwd):/ansible/playbooks \
    ansible-docker site.yml

Running in Windows

Add the following lines to your Powershell profile to make a function you can call directly:

function ansible-playbook {
  $allArgs = $PsBoundParameters.values + $args
  docker run --rm -it -v ${pwd}:/ansible/playbooks ansible-docker $allArgs
}
You can’t perform that action at this time.