Configure Docker on Managed Node and configure container as Web-Server using Ansible.

Shailja Tripathi
5 min readAug 5, 2020

--

What is Ansible?

Ansible is a simple tool for automation, to be specific, configuration management, application deployment, cloud provisioning, and many other IT needs.

Ansible supports one to many connections and automates tasks at a time. For instance, if we have 100 servers with the heterogeneous environment, using ansible we just have to tell it “what to do?” and “where to do?”, here we can provide it with a list of remote servers doesn’t matter how much. Ansible with its intelligence will do the desired task, which means, it automatically finds “how to do it?”.

Ansible works on push mechanism which means, it doesn’t require any agent program running on the remote system which is controlled by Ansible. This is the difference between its competitor Chef, puppet, and many more.

The system in which we have ansible installed is called controller node and the systems which we are controlling are called managed nodes. So, in a nutshell ansible is just a software where we have to mention what to do? It will automatically find how to do it? and completes the desired work.

What is 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.

Installation of Ansible:

Downloading it inside the Rhel v8 VM using python library installer pip and run the command:

pip3 install ansible

Creating Inventory:

Inventory file is like a database that will give information about manage nodes.

Here we can give any name to the file and can create it anywhere.

vim /etc/myhosts.txt

In this, we will give the IP, username, and password of our managed node. We can also add multiple IPs in the file if we have multiple managed nodes.

Configuring Ansible:

We will create a configuration file

mkdir /etc/ansible
vim /etc/ansible/ansible.cfg

In this we have provided the path of our inventory. To run this playbook we need to give ssh permission. This can be done via host_key_checking=FASLE.

To check the list of managed nodes:

ansible all --list-host

To check the connectivity between the controller node & managed node:

ansible all -m ping

To check the version of ansible and check the configuration file is added or not:

ansible --version

Ansible Playbook:

Ansible-playbook is a code file or say the main program file of ansible where we mention the hosts and tasks we have to perform on them. The snippet of code which perform a task is called play and when we write multiple hosts and their tasks in a file it’s called playbook. It works on YAML language.

vim docker_configuration.yml

Ansible code:

Creating a yum repository for Docker:

Installing docker using package module:

Start and enable the docker service and install the python for the docker:

Creating a directory in manage node:

Copying index.html to manage node:

Creating a container using httpd(Apache Web Server) image & expose the port:

Run the playbook:

ansible-playbook docker_configuration.yml

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.

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

Check the IP of that container.

Connect to this IP and see the web page.

Just one click and the setup is done, so what we have finally done is

  1. Configure yum on managed node for docker
  2. Installing docker
  3. Launch an container with httpd image, if it’s not there, it will automatically download.
  4. Then configured HTTPd web server by attaching the folder to document root of httpd webserver.
  5. Exposed the container on port 3333 so that clients can connect.

Thankyou For Reading!!!

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response