💥 Task Description →
👉 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
Firstly, I had installed Ansible on the top of Rhel 8 OS. Considering
that you know the installation of ansible I am directly jumping to the
use-case part that we have to perform.
So, you can see the inventory file which is named as ip.txt, in this file
I had provided the target node IP so that we can connect to the
target node we have with us. Also, you can see the configuration file
of ansible in which I had given the path of the inventory file I had and
some other default values. The location of configuration file is inside
the /etc/ansible directory.
You can take the help of ansible-doc file to see the syntax and
keywords used for the particular things you want to configure and
then you can apply those syntax accordingly in your yml file.
Refer to the figure given below :--
On the left side, we have our Managed Node on which we have to
make a directory and then create a .yml format file in which we have
to write the ansible code. On the right side, we have the Target Node
on which we have to apply all the features that has been asked.
Command which is used to compile or run the yaml file is
#ansible-playbook -v <name of yml file>
Where, v is used for the verbose.
Coming on to the task part we have to firstly install the Docker
software in our operating system.
To install the docker module we need to configure yum first, as you
can see in the code below that I had automated the yum
configuration under yum_repository.
Then I had used the command module to install the docker-ce in
Target Node.
In this part I had configured the docker services in the Target Node
with the help of ansible playbook.
On the left side of the picture you can see the code that I had used in
docker.yml file. This code has been written with the help of ansible-
doc file.
In this part I had installed the Python SDK of Docker and also I had
pulled a httpd image from the DockerHub.
In this image as you can see I had created a workspace or the
directory named as wsp and then in next part I had created the
web.html file given the input of the content inside it.
In this image as you can see I had setup the httpd webserver for docker container, exposed the ports and given the volumes. On the left side you side the compilation of yml file.
Now in the Target Node by the inspect command you can see the IP
of the docker webserver IP
Going on to the firefox just copy the webserver IP and then the
webserver file name.
You will get the desired output or the content that you had given in
the web.html file.
No comments:
Post a Comment