This is a inofficial docker image for ansible based on alpine linux, because an official image is not available.
This image is available on docker hub.
Besides an full ansible installation, this image contains openssh-client to connect to remote hosts.
The follwoing tags are available:
latest
- latest version of ansiblex.y.z
- ansible version x.y.z, e.g. 2.16.0
To connect safely to remote hosts, the ssh key should be mounted into the container. The ssh key should be mounted to /root/.ssh/*
. Further the ansible inventory file and the playbook directory should be mounted into the container. The inventory file should be mounted to /etc/ansible/hosts
and the playbook directory to /ansible/playbooks/*
.
An generic example for the usage of this image is shown below.
user@host:~$ docker run --rm -it \
-v ${HOME}/.ssh/:/root/.ssh/ \
-v <path/to/inventory>:/etc/ansible/hosts \
-v <path/to/playbooks/folder>:/ansible/playbooks/ \
ansible <tool> <playbook>
An more specific example for the usage is shown with the ansible-playbook command below.
user@host:~$ docker run --rm -it \
-v ${HOME}/.ssh/:/root/.ssh/ \
-v ${HOME}/ansible-playbooks/inventory.yaml:/etc/ansible/hosts \
-v ${HOME}/ansible-playbooks/playbooks/:/ansible/playbooks/ \
ansible ansible-playbook ping.yaml
To make the usage of this image more convenient, you can create for each tool an alias in your .bashrc
or .zshrc
file.
alias ansible-playbook='docker run --rm -it -v ${HOME}/.ssh/:/root/.ssh/ -v ${HOME}/ansible-playbooks/inventory.yaml:/etc/ansible/hosts -v ${HOME}/ansible-playbooks/playbooks/:/ansible/playbooks/ ansible ansible-playbook'
The alias above can be used like the original ansible-playbook command.
user@host:~$ ansible-playbook ping.yaml