
Docker Configuration using Ansible Playbook
How to Configure Docker Managed node(s) using Ansible Playbook ?
Ansible is a tool for configuration management. Its provided by Python internally & comes with Python 3. Hence for Ansible installation we need to use pip3 python package manager. pip3 install Ansible is the command to install Ansible. We can verify installation using Ansible — version command. This should be the latest Ansible version i.e. 2.9.11.
Traditional Automation Approach:
It uses imperative programming languages such as python,perl which handles following 1. What to do ? 2. How to do ? — For handling this the script is not intelligent enough to know the commands which needs to be run on different O.S. eg to install firefox on Ubuntu/Rhel8 the command is not known to programming language this 2nd part is effectively handled using Intelligent Automation approach
Intelligent Automation approach :
This uses declarative language & is independent of the O.S. configuration on which it needs to be run. It’s intelligent enough because it knows how to do the configuration/installation of softwares on other O.S. platforms. e.g. Ansible
Ansible uses inventory which is list of IP addresses of managed nodes. By default Config file name is ansible.cfg , its stored under /etc. Pip does not create config file during Ansible installation.
Ansible has 2 types of nodes .
- Controller node — On this node Ansible is installed.
- Managed nodes — These nodes are managed by controller node on which Ansible performs configuration (software installation,any other config changes)
- Inventory — This is a database which stores IP of managed nodes which is required by Ansible config file.
- Ansible config file contains the path of inventory file to access managed nodes & perform configurations. Inventory path is given under defaults header. e.g.
Below is an example
[defaults]
inventory =/etc/myhosts.txt
where myhosts.txt contains IP of managed nodes
Internal protocol of Ansible uses SSH for Linux systems. In order to access managed nodes we need to get SSH credentials from controller node. We can use ssh password setup for that. rpm file can be downloaded from internet for it & we can use below command for installation
rpm -ivh <rpm file name>
Controller Node

Ansible version

ansible config file

We can list inventory using below command on controller node

ansible all — list-hosts

Ensure Connectivity to internet

To check connectivity with managed node(s) we can use below command

Ansible uses push mechanism, to config managed nodes. It pushes the code to managed nodes and run it there. Ansible do not require any software to run on managed node. This is known as agent less. Other configuration management tools like puppet and chef uses pull mechanism. They pull the code from the controller node and run it. Managed node should have puppet or chef installed on it. They are known as agents.
When Ansible runs the code on managed node it first check the current state and match it with the desired state. If current state matches with desired state, ansible do not run the code, but if they don’t match ansible run the code and configure managed nodes according to desired state. This is known as Idem-potency
Ansible Playbook execution


Managed Node after Docker Configuration :
we can check repository on Managed Node as follows :


Managed Node after Apache Web Server set up
We can verify successful installation of Apache Web Server on Managed Node as under :


We can verify the file copy operation on Managed Node as below:

Status of Web Server

Web page launched finally !!
We can verify the page using public IP of managed node through controller node as follows :

This way we can configure Docker on management nodes using Ansible tool. Ansible uses modules which is intelligent enough to perform how to do action on managed nodes. This makes our life simpler as we don’t have to learn commands of individual systems as Ansible managed that part using intelligent modules.