How to get started with dockerized Ansible

Hey there! This blog post will discuss how we will be able to get started with Ansible setup using docker containers.

The dockerfile

The docker file that you will need in order to build the Ansible container is shown below.

FROM ubuntu:18.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
 apt install -y \
 curl \
 iproute2 \
 software-properties-common \
 iputils-ping
RUN add-apt-repository --yes --update ppa:ansible/ansible
RUN apt install -y ansible
WORKDIR /ansible_dir
CMD [ "/bin/bash" ]

Building the container and running it

Use the following command to build the container after you have placed the dockerfile in a directory of choice:
$ sudo docker build -t ansible_container:1 .
Note: Don't forget that there is a period at the end of that command!

Once that is done, we can run the docker container using the following command:
sudo docker run -v <full path to any directory you want to mount to the container>:/ansible_dir -it ansible_container:1 bash

The results of these commands will create a container called ansible_container:1 and mount a directory of choice to the container under 'ansible_dir', and enter the bash shell of the container.

The reason to mount the directory to the Ansible container is to persist volumes. If you want to override Ansible default etc / inventory / configuration, make sure that you have the etc and inventory directories in the mounted volume and have your own custom ansible.cfg file. This blog post does not discuss details on how to use Ansible, but only provides the code that you will need in order to set up a containerized Ansible host.

Hope this helps! ☺️

Previous
Previous

Kubernetes - Weave Network Overlay

Next
Next

How to set up your own Kubernetes Cluster?