DOCKER AUTOMATION USING ANSIBLE

DOCKER AUTOMATION USING ANSIBLE


No alt text provided for this image

To configure and start Docker services and configure Apache Webserver on it using Ansible playbook.

First of all We will go through the basics terms if someone had missed my previous article.

WHAT IS 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. Basic terms in ansible:

  • Controller Node : In Ansible, the node from which we do all configurations is Controller Node. In this we must have python installed and then we install Ansible. We can run Ansible commands and playbooks by invoking the ansible or ansible-playbook command from any controller node.
  • Managed Node : In Ansible, the nodes in which we want commands to be performed by automation are Managed nodes. No setup is needed in managed nodes.
  • Inventory : It is a list of managed nodes. An inventory file is also sometimes called a "hostfile". An inventory specifies information like IP address, username and password, etc for each managed node. 
  • PlayBook : Playbook contains ordered list of tasks, saved so we can run those tasks in that order repeatedly in different managed nodes. Playbooks are written in YAML and are easy to read, write, share and understand.

WHAT IS DOCKER ?

Docker is a set of platform as a 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 A WEBSERVER ?

A web server is server software, or hardware dedicated to running this software, that can satisfy client requests on the World Wide Web. A web server can, in general, contain one or more websites. A web server processes incoming network requests over HTTP and several other related protocols. The primary function of a web server is to store, process and deliver web pages to clients. The communication between client and server takes place using the Hypertext Transfer Protocol (HTTP). Pages delivered are most frequently HTML documents, which may include images, style sheets and scripts in addition to the text content. 

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 httpd container and expose it to the public
  • Copy the html code in /var/www/html directory and start the web server

Step 1 : Check whether the ansible is installed on the OS.

No alt text provided for this image

Step 2 :Ansible Configuration file

mkdir /etc/ansible
vim etc/ansible/ansible.cfg
No alt text provided for this image

Step 3 : Creating Inventory

vim ip.txt
No alt text provided for this image

Step 4: Creating playbook

No alt text provided for this image

Step 5: Running the PlayBook

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

Output of the Container Server as we can access the server from the Browser

No alt text provided for this image

Hence we can configure any number of Managed Nodes in which we can configure all the same things by just executing the single PlayBook.

***** THANK YOU FOR READING!! *****

要查看或添加评论,请登录

Suyash Dahake的更多文章

社区洞察

其他会员也浏览了