This image execute ansible
and let you pass your ansible's arguments directly to the container.
You need to mount your ansible folder in /ansible
Supposing you execute the container within your ansible folder you can run:
docker run -it --rm \
-v $PWD:/ansible \
authkeys/docker-ansible --ask-become-pass --ask-pass playbook.yml
You can pass some envs to the container:
SSH_KEY
name of the SSH key you want to use. No default. It must exists in /root/.sshPYTHON_REQUIREMENTS
path to a file that contains the python modules needed by ansible. Default valuerequirements-pip.txt
. If file exists, the commandpip3 install -r <file>
is executedANSIBLE_REQUIREMENTS
path to a file that contains ansible modules. Default valuerequirements.yml
. If file exists, the commandansible-galaxy install --force -r <file>
is executedANSIBLE_PRE_PLAYBOOK
path to a playbook file. No Default. If file exists, the commandansible-playbook ${ANSIBLE_PRE_PLAYBOOK_OPTS} <file>
is executed.ANSIBLE_PRE_PLAYBOOK_OPTS
contains optional arguments passed to pre-playbook execution.
docker run -it --rm \
-v $PWD:/ansible \
authkeys/docker-ansible --ask-pass playbook.yml
docker run -it --rm \
-e SSH_KEY=id_ed25519 \
-v $HOME/.ssh:/root/.ssh \
-v $PWD:/ansible \
authkeys/docker-ansible playbook.yml
If your SSH key is protected with a passphrase, you will be prompted to enter it
docker run -it --rm \
-e SSH_KEY=id_ed25519 \
-e PYTHON_REQUIREMENTS=/python/requirements.txt \
-v requirements.txt:/python/requirements.txt \
-v $HOME/.ssh:/root/.ssh \
-v $PWD:/ansible \
authkeys/docker-ansible playbook.yml
docker run -it --rm \
-e SSH_KEY=id_ed25519 \
-e ANSIBLE_REQUIREMENTS=/extra/requirements.yaml \
-v requirements.yaml:/extra/requirements.yaml \
-v $HOME/.ssh:/root/.ssh \
-v $PWD:/ansible \
authkeys/docker-ansible playbook.yml
We need to run a playbook to add remote hosts' public keys to known_hosts before executing our playbook
docker run -it --rm \
-e ANSIBLE_PRE_PLAYBOOK=ssh_keyscan.yml \
-e ANSIBLE_PRE_PLAYBOOK_OPTS=--forks=1 \
-e SSH_KEY=id_ed25519 \
-v $HOME/.ssh/id_ed25519:/root/.ssh/id_ed25519:ro \
-v $PWD:/ansible \
authkeys/docker-ansible playbook.yml