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.
STEP-2:- Get the IP of Target Node and put it on the ansible inventory file with USER NAME & PASSWORD.
vim inv.txt
STEP-3:- Update the Configuration file of ansible, File Directory:-
vim /etc/ansible/ansible.cfg
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:-
vim docker.yml
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:-
vim web.html
STEP-7:- Now we have to run our ansible playbook. Command:-
ansible-playbook docker.yml
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:-
THE END..
HURAAY FINALLY WE HAVE COMPLETED OUR TASK. HOPE IT MAY HELP YOU.