Deploy Ansible with Docker
There are many benefits to containers; in this blog post, I will show you how to deploy a Docker container to build a consistent Ansible environment that can be shared across your DevOps organization or used as your personal sandbox.
Running Ansible in a container is a low-maintenance solution that can be shared consistently across your team. Any team member who is running the Docker engine can simply run your container.
Installing Docker
The first thing we need to do is install Docker, as of this post the latest release is Docker version 20.10.7, build f0df350.
Ubuntu 18
sudo apt-get update
sudo apt install docker.io -y
macOS
https://docs.docker.com/docker-for-mac/install/
Windows
https://docs.docker.com/docker-for-windows/install/
Creating your Ansible container
Authoring your Docker file
Now it is time to build a Dockerfile. The Dockerfile contains the steps needed to build your container to your specifications.
In this case, our base OS will be Ubuntu 18, and installed is Ansible with related dependencies.
FROM ubuntu:18.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y gcc python-dev libkrb5-dev && \
apt-get install python3-pip -y && \
pip3 install --upgrade pip && \
pip3 install --upgrade virtualenv && \
pip3 install pywinrm[kerberos] && \
apt install krb5-user -y && \
pip3 install pywinrm && \
pip3 install ansible
Build your Docker image
docker build -t ansible:latest .
Run your Docker container
docker run -it ansible
Conclusion
Docker is an elegant solution to tool maintenance, no longer do you need dedicated virtual machines to manage automation tooling.