Ansible playbook that enables docker and html code that expose to public.

task-10

“🔰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

Configure the Package for the Docker Installation

First of all we have to make a repository in order to install the docker software.

Installing the Docker Software

Now, we have two options for installing the docker software.

First option we can directly use the package module of ansible, but after this process an error will occur. This can’t help us to install a perfect docker software version. As we know installation of docker software can also be done by the help command module , But here in this case we can use the shell module instead of command module because in command modules we cannot use the keywords of the shell in shell module we can do so (for –nobest).

Second option is that we can install the docker software and look at the version of the installed docker version. Now we can copy this same version and we will run the package module with same version which will download the perfect docker software.

Starting the Docker Service

Now let’s start the docker service by the help of ansible module. Now we are going to pull the image of httpd. So, we are going to use a module for pulling an image of docker by the help of docker image but we will face a problem as it will need a python module named “docker-py”. For installing this python module we need a pip module which is provided by ansible.

Now copy the (.html)code to the perfect place !!

We will create a .html page and transfer this file by the help of copy module. We have to make sure we have copied this file at a secured place.

Lunch the Docker Container and also expose it !!

Now we will start the docker container by the help of image HTTPD but when this image will start we will expose this image at a port and while starting we will attach a destination to this image where the .html file is located.

Allow the firewall for the port through which we have exposed that container

Now we have to allow the port through which the docker image is exposed.

https://raw.githubusercontent.com/mhimavarsha/task10/main/docker.yml

check github for the code reference

In a phase of learning;)