DOCKER CONFIGURATION WITH ANSIBLE
Hey connections!!
TASK DESCRIPTION :
Write an Ansible PlayBook that does the following operations in the managed nodes:
1. Configure Docker.
2. Start and enable Docker services.
3. Pull the httpd server image from the Docker Hub.
4. Run the httpd container and expose it to the public.
5. Copy the html code in /var/www/html directory and start the web server.
FOR ACHIEVING ABOVE TASK WE HAVE TO FOLLOW CERTAIN STEPS WHICH IS MENTIONED BELOW :
STEP 1 :
Ansible is an automation tool and for doing certain automation , 1st of all we have to give the proper information of our target node and this information is stored in some file and this file is known as "INVENTOTRY"
Here , I have created an inventory "ip.txt" and I had attached it on ANSIBLE CONFIGURATION FILE .
STEP 2 :
Now after adding our inventory to the ansible configuration file , then next step is the check the connectivity between Controller Node and Target Node .
For this we use a command
"ansible all -m ping"
After running the above command we get
which means We have successfully connected with our target node .
STEP 3 :
After connection now we have to write a playbook for ansible . for this first of all we have to make a workspace for it and here i made a folder "task1" and inside this folder i made a file with an extension of " .yml " and i named this file as "ansible_task.yml"
NOW , WE HAVE TO WRITE OUR PLAYBOOK FOR ANSIBLE
STEP 4 : YUM CONFIGURATION FOR DOCKER
STEP 5 : DOWNLOAD DOCKER
STEP 6 : START DOCKER SERVICE
STEP 7 : DOWNLOAD DOCKER SDK ON DOCKER HOST
STEP 8 : CREATING MOUNT PATH FOR DOCKER CONTAINER
STEP 9 : PULLING DOCKER IMAGE
STEP 10 : LAUNCHING DOCKER CONTAINER USING HTTPD IMAGE
STEP 11 :
After writing above playbook now it time to check the syntax and then run it .
FOR SYNTAX CHECKING :
"ansible-playbook --syntax-check ansible_task.yml "
FOR RUNNING :
"ansible-playbook ansible_task.yml "
STEP 12 :
After running above commands we get
Our playbook run successfully without any error .
Now lets check whether our desire work was done or not .....
- YUM IS CONFIGURE SUCCESSFULLY
2. DOCKER WAS SUCCESSFULY DOWNLOADED
3. OUR DOCKER SERVICE WAS STARTED
4. MOUNT PATH WAS CREATED SUCCESSFULLY
5. DOWNLOAD DOCKER SDK IN DOCKER HOST
6. PULLING DOCKER IMAGE AND LAUNCHING DOCKER HTTPD IMAGE
STEP 13 : COLLECT THE IP AND BROWSE IT ON BROSWER
Finally our task are successfully done .
Thank you for visiting !!
Have A Nice Day !!
DevOps Engineer at Amdocs
4y🔥🔥