Automation with Ansible — Common Terms and Setting up Docker

This is the second article in the Automation with Ansible series. For the first article, please refer to this link.

In this series, we will be looking at different ways in which Ansible can be used to implement automation in the IT industry

Photo by Glenn Carstens-Peters on Unsplash

How do we begin working with Ansible?

Common Terms in Ansible

Control node/Controller node

Managed nodes/Target node





Setting up Docker using Ansible

  • Install Ansible on the control node. (Refer here for details on installation).
  • Install sshpass on the control node. Typically, when we execute commands remotely through SSH, we are prompted for a password for every command. sshpass allows us to avoid this.
# Contents of ansible.cfg
inventory= /etc/ansible/hosts.txt
  • IP address
  • The username of the account with which we will be remotely executing commands. This is given as the value of the ansible_user property.
  • The password of the username. We can enter this directly for now, but there are more security measures to store these passwords. This is given as the value of the ansible_password property.
  • The protocol used by the target node and the control node to communicate. This is given as the value of the ansible_connection property.
# Contents of inventory
<IP-addr of target nodes> ansible_user=<username> ansible_password=<password> ansible_connection=ssh
ansible all -m ping
  • Configure the YUM repository
  • Download the Docker-CE version and install it
  • Launch a container with httpd web server setup
  • Copy a webpage into the default Document Root of the web server in the container

Creating the directory and mounting the ISO file

Creating a directory to save copies of files from the control node

Configuring YUM repo using packages from AppStream and BaseOS of ISO

Configuring YUM repo source for Docker

Installing Docker and docker-py package

Pulling httpd Docker image from Docker Hub and Starting Docker Container with httpd image

But wait! We can’t run the playbook right away!

ansible-playbook --syntax-check docker_playbook.yml
ansible-playbook -v docker_playbook.yml
Figure 1. Sample output on the control node terminal
Figure 2. Sample output for the target node
Figure 3. Successfully accessing the webpage


In the next article, let’s see a similar setup — Setting up a Hadoop Cluster with Ansible.