Configuring Docker and httpd using Ansible Playbook

Lakshmi Priya Patro
4 min readApr 11, 2021

Task Description

🔰Write an Ansible PlayBook that does the following operations in the managed nodes:
🔹 Configure Docker
🔹 Start and enable Docker services
🔹 Pull the httpd server image from the Docker Hub
🔹 Run the docker container and expose it to the public
🔹 Copy the html code in /var/www/html directory and start the webserver

What is Ansible?

Ansible is a software tool that provides simple but powerful automation for cross-platform computer support. It is primarily intended for IT professionals, who use it for application deployment, updates on workstations and servers, cloud provisioning, configuration management, intra-service orchestration, and nearly anything a systems administrator does on a weekly or daily basis. Ansible doesn’t depend on agent software and has no additional security infrastructure, so it’s easy to deploy.

What is Ansible playbook?

An Ansible playbook is an organized unit of scripts that defines work for a server configuration managed by the automation tool Ansible. Ansible is a configuration management tool that automates the configuration of multiple servers by the use of Ansible playbooks.

What is webserver?

A web server is a computer that runs websites. It’s a computer program that distributes web pages as they are requisitioned. The basic objective of the web server is to store, process and deliver web pages to the users. This intercommunication is done using Hypertext Transfer Protocol (HTTP).

What is docker?

Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications.

Lets move on to our practical:

First we have to create VM for controller node and target node.

Step-1: Install ansible and check the ansible version in your managed node

yum install ansible -y

Step-2: Check IP Address of your target node

Step-3: Create a group of IPs in /root/ip.txt in which we have to write the Target Node IP as a host in Controller Node. Give the Username and password of the target node.

By creating groups of IP known as Inventory can helps us to do automation that Node which are in group.

Step-4: To run the playbook we need to provide ssh permission.

For this we need to give the path of the inventory file in ansible configuration file(/etc/ansible/ansible.cfg)

Step-6: Now, we are good to create our own playbook to run the code so create an ansible playbook named docker.yml

Step-7: These are the following tasks we have assign in the playbook.

Step-8: Create an HTML file docker.html

Step-9: Run the playbook before launching the container in the target node

Step-10: Give the target ip with the filename in the browser

Hence the task was successfully completed.

Thank You!!

--

--