Configuring Docker With Ansible(RH294)

Configuring Docker With Ansible(RH294)

Ansible(RH294) Task 1:

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 httpd container and expose it to the public.

🔹 Copy the html code in /var/www/html directory and start the webserver.

Ansible:

Ansible is an open-source software provisioning, configuration management, and application-deployment tool enabling infrastructure as code. It runs on many Unix-like systems and can configure both Unix-like systems as well as Microsoft Windows.

Docker:

Docker is a set of the platform as service products that use OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries, and configuration files; they can communicate with each other through well-defined channels. 

What is httpd?

The Apache HTTP Server, colloquially called Apache, is a Web server application notable for playing a key role in the initial growth of the World Wide Web. Originally based on the NCSA HTTPd server, the development of Apache began in early 1995 after work on the NCSA code stalled. Apache quickly overtook NCSA HTTPd as the dominant HTTP server and has remained the most popular HTTP server in use since April 1996.

Ansible playbook:

An Ansible playbook is an organized unit of scripts that defines work for a server configuration managed by the automation tool Ansible. Ansible is a configuration management tool that automates the configuration of multiple servers by the use of Ansible playbooks.

Pre-requisites:

1) Installation of Ansible:

 In the RedHat8, Python3 is already installed. So, we have to install ansible on the top of python3. For installing the Ansible use the following command:

# pip3 install ansible

After that, You can check the version of Ansible, for the check whether ansible is installed properly or not

For checking the version :- ansible --version

No alt text provided for this image

2) Configuration of Ansible:

A) In the /etc/ansible_host.txt file we have created a group of the Managed Node Ip as a host in Controller Node. By this approach, we can control the automation that Node which is in the group. After the IP, give your username and password of that Managed Node.

No alt text provided for this image

B) Ansible works against multiple systems in your infrastructure at the same time. It does this by selecting portions of the systems listed in Ansible’s inventory file. You can specify a different inventory file using the -i <path> option on the command line. Not only is this inventory configurable, but you can also use multiple inventory files at the same time.

No alt text provided for this image

By using the following command you can the list of hosts you have:

No alt text provided for this image

We need to check, that all managed node is properly connected to the controller node or not. For that use the following command.

No alt text provided for this image

 I have created docker.yml file where i have written the ansible automation code for installing docker,pulling the httpd image and exposing the container.

No alt text provided for this image
No alt text provided for this image

Once you have created your code you can use ansible-playbook <docker.yml> --check to check the errors this command will not make any change in the managed not but it will show al the process that will happed when you will execute your playbook. use ansible-playbook <docker.yml> to run the file.

No alt text provided for this image

as you can see our playbook is successfully running, now we will go to our managed node and check whether the repository of docker has been created or not and we will also check the status of the docker.

No alt text provided for this image
No alt text provided for this image

now as our repo has been created and service is also active, we will further check whether our container has been launched or not.

No alt text provided for this image

As you can see that we have launched our container myos successfully. You can also check the ip of that container.

Now you can connect this IP and see the web page.

No alt text provided for this image






Thank you!!


To view or add a comment, sign in

More articles by Shailly Shah

Insights from the community

Others also viewed

Explore topics