Inspired by: https://github.com/willhallonline/docker-ansible
An "ansible" user is created inside the container and used to execute commands. Change the "/home/user" path with your local environment.
docker run --rm -it \
--mount type=bind,source="$(pwd)",target=/ansible \
--mount type=bind,source=/home/user/.ssh,target=/home/ansible/.ssh \
omnys/ansible:2.8.17.3 \
bash
docker run --rm -it \
--mount type=bind,source="$(pwd)",target=/ansible \
--mount type=bind,source=/home/user/.ssh,target=/home/ansible/.ssh \
omnys/ansible:2.8.17.3 \
ansible-playbook playbook.yml
If you need to execute aws cli commands, and you want to load local aws profiles, add a custom mount:
... --mount type=bind,source=/home/user/.aws,target=/home/ansible/.aws ...
... --volume $SSH_AUTH_SOCK:/ssh-agent --env SSH_AUTH_SOCK=/ssh-agent ...