Ubuntu-based Docker image for running Ansible playbooks with support for SSH, sudo, and external inventory mounts.
- Put
configs/ansible.cfg
andconfigs/inventory/hosts.ini
on the host. - Optionally add playbooks under
configs/
.
make build
make up
# SSH in (optional)
ssh -p 2222 ansible@localhost
# Or exec a shell
make sh
docker build -t ansible-ctrl ./docker
# Start the container (SSH exposed on host port 2222)
docker run -d --name ansible-ctrl \
-p 2222:22 \
-v "$PWD/configs":/configs:rw \
-v "$PWD/logs":/var/log/ansible:rw \
-v "$PWD/ssh/authorized_keys":/home/ansible/.ssh/authorized_keys:ro \
ansible-ctrl:latest
# Open a shell inside the container
docker exec -it ansible-ctrl bash
# From that shell, run Ansible using your mounted config/inventory
ansible --version
ansible -m ping all
ansible-playbook /configs/playbooks/site.yml
docker compose up -d
docker compose exec ansible bash
# then run Ansible:
ansible -m ping all
ansible-playbook /configs/playbooks/site.yml
ansible --version # confirms which config file is used
ansible -m ping all
ansible-playbook /control/playbooks/site.yml
-
If configs/ansible.cfg exists, it is used; otherwise the image default /etc/ansible/ansible.cfg is used.
-
ssh/authorized_keys (host) is mounted to the ansible user for SSH access.
-
The ansible user exists inside the container; add more users only if you extend the entrypoint.
-
PermitRootLogin no
, key-only auth via mountedssh/authorized_keys
.