Setting up Docker using Ansible

What will be our aim

🔰Write an Ansible Playbook that does the following operations in the managed nodes:
🔹 Configure Docker
🔹 Start and enable Docker services
🔹 Pull the httpd server image from the Docker Hub
🔹 Run the docker container and expose it to the public
🔹 Copy the html code in /var/www/html directory and start the web server

In order to do this first we will require to First make sure ansible is installed in our OS.

We can check this by using command : ”ansible — version”

Note: We are using Red hat Enterprise Linux 8

Now as our ansible is installed properly now we have to update the inventory file in order to control our target node.

We will give this node name webserver as we are going to make it a webserver.

Now we will check the connectivity with the target node.

As our target node is connected properly with the controller node now we can run our playbook in order to install docker and setup the webserver.

Playbook URL: https://github.com/ritikbobade/Docker-playbook-ansible

As you can see the playbook is successfully ran without error now we can check the docker container is launched successfully or not.

So the container is launched successfully now lets grab the ip of the container in order to check the webserver is running properly or not.

As we have the ip now we can check the webserver is set up successfully or not.

Thus we can see our test page successfully we have completed the task .🤩🤩