Ansible Combination with Docker

Ayush Gupta
4 min readAug 3, 2020

--

INTRODUCTION TO ANSIBLE :-

Ansible is an open source community project developed by Red Hat, it’s the simplest way to automate IT. Up to know Ansible is the only automation software that can be used across entire IT teams from systems and network administrators.

Ansible is basically an Intelligence software it’s base language is the Python. This Software is used for Controlling multiple system from one system.

Here what I meant by Automation is that this software require “What to do” as commands and “how to do” is not required for Ansible. This software will configure by it’s automation that which OS is install on that system and what it’s commands.

*An Example →We want to install any software on a system and we don’t know which OS is installed on this system. Now here the role of ansible comes into play you just need to give some commands or a playbook (like bash scripting shell) containing all the commands required for ansible.

→ Playbooks are ansible script written in YAML language. You can run Playbook using a command [ ansible-playbook filename.yml ]

Going back to above example, In the playbook we just require to pass what to do means ask ansible “hey ansible download firefox for me on 192.168.43.34 (one of the system IP I want to manage)”. I need to pass this in ansible keywords/ in it’s language and It will do complete process for me.

Talking about how ansible works, It uses RAL (Resource Abstract Layer) for abstraction. Which means what ever commands ansible run on different OS are hidden by this layer.

INTRODUCTION TO DOCKER:-

**To setup operating system we have four technologies -

1). Bare Metal

2). Virtualization

3). Cloud

4). Containerization

*In Bare Metal , Virtualization and Cloud technologies operating system takes 1/2 hour to setup OS. If any reason OS is crashed then it will again take same time to setup this. But in Containerization technology OS takes less than only some seconds to setup this. It is very helpful in many cases.

  • Docker is tool which works on containerization technology. Docker takes less than 1 second to set up all environment of OS. Docker is very fast to handle this . One of the reason is docker use base OS components.

Now, I Presume that You have a little bit of info about Docker and Ansible

Here I start my Project:

  1. My Inventories/ Nodes I need to mange -

2. My Ansible Configuration File

Tasks I have performed:

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

  1. Complete Task are performed by making a playbook, here is the playbook screenshots

2. Running Ansible Playbook

3. Checking services on my managing node

4. HTML Website launched through sever using port 8080:80

--

--