ANSIBLE PLAYBOOK TO CONFIGURED WEB SERVER DOCKER CONTAINER.
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.
STEP-2:- Get the IP of Target Node and put it on the ansible inventory file with USER NAME & PASSWORD.
STEP-3:- Update the Configuration file of ansible, File Directory:-
STEP-4:- Now check the list of the Hosts and the Connectivity with your Target Node. Command:-
ansible all --list-hosts
ansible all -m ping
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:-
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:-
STEP-7:- Now we have to run our ansible playbook. Command:-
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-
STEP-9:- Now fetch the IP of the Docker Container and use the URL to see your web page:-
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.
Ansible Playbook for Docker Configuration. Contribute to Sarvjeet-Jain/DOCKER_ANSIBLE development by creating an…