Integration of Docker and Ansible
Greetings everyone! Today we are going to solve the use case or the following task:
Write an Ansible playbook that performs the following actions on 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
To do this you need to know about some of the basic concepts of Ansible, Docker and Linux systems.
Ansible
Ansible is an Automation tool. What do I mean by automation? It can be any one of Infrastructure Automation, Cloud Automation, Security Automation, Application Automation, many others!! . With Ansible you can configure Routers, Clusters, Webservers, Applications, Docker, and anything. We know how to configure many services or clusters if we can make all the configurations the most intelligent configurations (but we donāt have to know how and where to do it, we just need what to do ! ) in a single click! That's what Ansible is.
Docker
Docker is a famous container tool. with the help of Docker we can turn on our containers (which is like OS) in 1seconds and can do whatever operation we need. We can run our codes, programs to start our servers.
Now in this blog we will know how to launch our containers using Ansible and then we start to deploy our websites on Docker and expose it to public.
From the controller node, we need to configure the managed node and install the docker there, for this we need to create a repository so that we keep the downloading URL of our docker. Since I only have two managed nodes, we can enter the IP of all or managed nodes in the host section.
*Now follow these steps in the Controller Node -
1- Check the ansible version installed on the controller node with the command āansible ā versionā
2- Check the inventory file.
3- Check the configuration file of Ansible.
4. Now, Ansible is installed and configured successfully. We now check the list of inventories by following commands :
5.To check the connection with the managed node, we use: āansible all -m pingā
6. Create a docker_webserver.yml file for playbook and write following commands :
7.Run the AnsiblePlaybook by using the command-
OUTPUT will be -
Now, the container is successfully created and configured as the webserver. Letās access the webpageā¦
Manage nodes is working properly ā¦ā¦. thatās the power of Ansibleā¦
š¹ Thanks for reading ā¦ š¹
š¹ keep sharing š¹