Automation Of WebServer On Docker Using Ansible

Problem statement

Write an Ansible PlayBook that does the following operations in the managed nodes:

What is Ansible?

Ansible is an open-source automation tool, or platform, used for IT tasks such as configuration management, application deployment, intra service orchestration, and provisioning. Automation is crucial these days, with IT environments that are too complex and often need to scale too quickly for system administrators and developers to keep up if they had to do everything manually.

Why Ansible?

Ansible is an Agent less tool that means we don’t need to install it on the managed node just installed on the controller node and start working with ansible. Ansible is a very intelligent tool and its intelligence comes from modules. As an IT Admin, we don’t have to remember all OS commands just tell which package you wanna install and ansible will do that thing for you!

What is the playbook file?

Playbooks are the files where the Ansible code is written. Playbooks are written in YAML format. YAML stands for Yet Another Markup Language. Playbooks are one of the core features of Ansible and tell Ansible what to execute. They are like a to-do list for Ansible that contains a list of tasks.

Docker:

Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and deploy it as one package.

Prerequisites

First, we have to install Ansible in Manager Node

pip3 install ansible

Ansible hosts.txt file

vim /etc/hosts.txt

Inventory

vim /etc/ansible/ansible.cfg

1.Creating a Yum repository

For installation of docker, first, we have to configure yum which allows us to automatically install or update packages.

     ansible-playbook yumconf.yml
output

2.Creating a Yum repository for Docker and to enable docker services

Now we need to download docker from the provided URL and to tell yum to install docker. After installing docker, we have to start our docker services which we perform with the help of a service module

ansible-playbook dockerconf.yml
output

3. Build DockerImage and to copy HTML, DockerFile to Manage Node

Now we have to build a docker image and launch a container using that image which has web-server configured. It uses centos as a base OS Also, we’ve installed httpd server and started its services. And I’ve created an html webpage to see if everything works properly.

ansible-playbook dockercont.yml
output
output