🔹 Task 1 — Ansible🔹
STEPS TO DO THIS TASK :
🔹 Configure Docker
🔹 Start and enable Docker services
🔹 Pull the httpd server image from the Docker Hub
🔹 Run the httpd container and expose it to the public
🔹 Copy the html code in /var/www/html directory and start the web server.
So lets start this task. First we have to create VM for Controller Node and Managed Node. As you can see in the below figure i am using Redhat VM as Controller Node (CN) where as Ansible Managed Node is for Managed Node.(TN)
Note: Managed Node is also called as Target Node
You can install ansible via pip command as it cam from python pip install ansible. after that you can check the version of Ansible.
We can create a group of IP in /root/ip.txt, in that you have to write that Managed Node Ip as a host in Controller Node. Give your Username and password of that Managed Node. By creating groups of IP known as Inventory can helps us to do automation that Node which are in group. As you can see there are three groups below in the figure. In all the groups we have a single Managed Node IP. If you want to do automation/configuration on multiple Managed Node then you can give their Ip in one of the Group. You can give any name to group.
Before running your playbook you need to check that all the Managed Node is connected or pingable with the Controller Node or not. This can be checked by following command. Those Managed Node IP is connected with Controller Node that only
Now, we are good to go for creating our own Playbook to run the code. Generally, Ansible Support YAML language in playbook. So, i have created two files one is a playbook ansible.yml and the other is my.html which we will be copying inside the container.
Also you need to give the path of ip.txt (IP data) in this /etc/ansible/ansible.cfg file. To run this playbook we need to give ssh permission. This can be done via host_key_checking=FASLE. Also to disable command warnings you can give command_warning=FALSE.
Codes inside ansible.yml is explained in detailed way in the following image.
To run this playbook you need to write ansible-playbook playbook_name.yml
After Successfully running the playbook, you can check the container whether it is launched successfully or not.
As you can see that we have launched our container mywebserver successfully. You can also check the ip of that container.
Now you can connect this ip and see the web page i.e my.html.You can see this Output This is automation using ansible !!! which i have written in my.html.
Hope You find this article interesting.
Thank You ! 😀😀😀😀