ANSIBLE PLAYBOOK TO CONFIGURED WEB SERVER DOCKER CONTAINER.

WELCOME

This Article contains, How we can create an Ansible Playbook that will configure the Docker inside the Target Node with web-server.

TASKS that we have to do here is-

1- CONFIGURED DOCKER.

2- START AND ENABLE DOCKER SERVICES.

3- PULL THE HTTPD SERVER IMAGE FROM THE DOCKER HUB.

4- RUN THE DOCKER CONTAINER AND EXPOSE IT TO THE PUBLIC.

5- COPY THE HTML CODE IN /VAR/WWW/HTML DIRECTORY AND START THE WEB SERVER.

So, let’s start our Practical Part:-

STEP-1:- Before Starting the Practical make sure that YOU SHOULD HAVE TWO NODES NAMED AS CONTROLLER & TARGET NODE RESPECTIVELY. AND IN CONTROLLER NODE YOU SHOULD HAVE ANSIBLE CONFIGURED.

1.1

STEP-2:- Get the IP of Target Node and put it on the ansible inventory file with USER NAME & PASSWORD.

1.2

STEP-3:- Update the Configuration file of ansible, File Directory:-

1.3

STEP-4:- Now check the list of the Hosts and the Connectivity with your Target Node. Command:-

1.4

STEP-5:- Now all setup has done and our Controller node also have connectivity with our Target Node. Let’s create an Playbook now. Command:-

1.5

Here I have used some module of Ansible such as yum_repository ( For creating Docker Repo in Yum Configuration file in our Target Node Because I by chance know my TN is RED HAT 8 OS), package (For installing the docker software), service ( For starting the Service of Docker), pip (To install the Docker Python), docker_image ( For downloading the docker image from the Docker Hub), copy (To copy my web page from CN to TN), docker_container (For starting the docker webserver container).

STEP-6:- Now we have to make our Web page in same directory.Command:-

1.6

STEP-7:- Now we have to run our ansible playbook. Command:-

1.7

You will get following output, if your code has no error and you have perfect connectivity.

STEP-8:- Now if you go to your Target Node, you will see-

1.8

STEP-9:- Now fetch the IP of the Docker Container and use the URL to see your web page:-

1.9

THE END..

HURAAY FINALLY WE HAVE COMPLETED OUR TASK. HOPE IT MAY HELP YOU.

THANK YOU FOR READING THIS ARTICLE. FOR MORE SUCH TYPE OF ARTICLE STAY CONNECTED.