Configure Web Server in Docker and start services using Ansible Playbook


STEPS TO PERFORM THE 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.

We can install ansible by:
pip3 install ansible (or) yum install ansible
After installing, we can check the version of Ansible.

ansible --version
We can create a group of IP in /root/ip.txt, in this write that Managed Node IP as a host in Controller Node. Provide the 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 we can see there are 1 group below in the figure. If we want to configurate on multiple Managed Node then we can give their IPs in one of the Group. we can give any name to group here. Since, we didn’t give any name, it consider as default.
ip.txt

192.168.29.28 ansible_user=root ansible_ssh_pass=redhat 
We need to give the path of ip.txt (Hosts data) to the ansible configuration file present in /etc/ansible/ansible.cfg. To run this playbook we need to give ssh permission. This can be done via host_key_checking=FASLE.
Before running the playbook we need to check that all the Managed Nods are connected and can be pinged from the Controller Node.ansible 
all --list-hosts
ansible all -m ping
We also need to install sshpass and for that we install the epel-release first and then install sshpass using the command: yum install ssshpass.
Now, we are good to go for creating our own Playbook to run the code. Ansible supports YAML language in playbook. Here we have created two files: one is a playbook web1.yml and the other is index.html which we will be copying inside the container.
Finally, we run the playbook :

ansible-playbook web1.yml
For details we can add the verbose keyword

ansible-playbook -vvv web.yml
After Successfully running the playbook, we can check the container whether it is launched successfully or not in Managed Node.

docker --version
docker ps
As we can see that we have launched our container Mywebserver successfully. We can also check the IP of that container.

docker inspect Mywebserver | grep IP
Now we can connect this IP and see the web page i.e index.html.

curl <ip>/filename.extension


Comments

Popular posts from this blog

GUI container on the Docker. Launch a container on docker in GUI mode. Run any GUI software on the container.

Fun commands in Linux