Repository name in Docker Hub: macunha1/ansible
This repository contains Jinja2 templates to specify Dockerfiles for multiple Linux distros, these templates are rendered and then dynamically build by GitHub Actions. Therefore, it is the composition of: templates + a script to render + the CI pipeline to build and push the images.
By default the following Linux distros are implemented. However, any future (version) release of any one of the supported distro can be easily added in the config to render a new Dockerfile.
- Debian: 10 (buster), 11 (bullseye);
- Ubuntu: 20.04, 22.04, 22.10;
- Alpine 3.10, 3.15, 3.16;
Pending: OpenSUSE and Fedora.
Ansible will be installed with the version specified on config.
All Docker images had Ansible installed through pip
.
To make sure the right version of Ansible is installed on container during
execution of tests, run a pip install ansible==$DESIRED_VERSION
.
Here comes a simplest working example:
FROM macunha1/ansible:alpine-3.11.5
RUN pip install ansible==2.3.4
ENTRYPOINT ["ansible-playbook"]
CMD ["-i", "inventory/awesome", "playbook.yml"]
Then,
docker build -f /path/to/Dockerfile -t awesome/docker-ansible:tag /any/build/context
Enjoy your Ansible image.
If you want to go directly to the point, without building your own custom image, just run:
docker run -it --name awesome-ansible-container \
-v ${HOME}/.ssh:/root/.ssh:ro \
# ... additional configurations
macunha1/ansible:alpine-3.11.5 \
-- -i inventory/awesome playbook.yml
There has been quite a few Ansible images for Docker (e.g., search in the Docker Hub), so why reinvent the wheel?
Simply, because most of them seems to be abadoned. Even the base of this fork from William Yeh
This repository was first created to give Confluent Kafka role a proper test suite. Previously, public images gave me a lot of issues, and I got tired of making workarounds to have a CI working for my roles.
If you're tired too of looking around and not finding what you need, join me and use these Docker images. Feel free to open issues and send PR, I will be happy to colaborate.
With Docker, we can test any Ansible playbook against any version of any Linux distribution without the help of Vagrant. More lightweight, and more portable across IaaS providers.
If better OS emulation (virtualization) isn't required, the Docker approach (containerization) should give you a more quicker setup to test your Ansible playbooks.
Feel free to fill an issue containing feature request(s), or (even better) to send me a Pull request, I would be happy to collaborate with you.
If this role didn't work for you, or if you found some bug during the execution, let me know.