Ansible automates and simplifies repetitive, complex, and tedious operations. Everybody likes it because it brings huge time savings when we install packages or configure large numbers of servers.

Its architecture is simple and effective. It works by connecting to your nodes and pushing small programs to them. These programs make the system comply with a desired state, and, when they have finished their tasks, they are deleted.

Ansible works over SSH and doesn’t require any daemons, special servers, or libraries to work. A text editor and a command line tool are usually enough to get your work done.

You simply describe your infrastructure in a text file (INI) and then all the information about the desired state of these machines are organized in playbooks. It is able to gather node information (such as IP addresses or Operating System details) into so-called “facts”, which help with the selective and automated provisioning of different configurations on the platform. All of this with a language that is very human readable without the need to write code or declaring explicit relationships.

It uses the playbook to describe automation jobs, and playbook uses a very simple language YAML.

To Know more about ansible , check my this blog : ANSIBLE : How Industries are solving Challenges using Ansible

Ansible Playbooks and Ad Hoc Commands

Ad hoc commands can run a single, simple task against a set of targeted hosts as a one-time command. The real power of Ansible, however, is in learning how to use playbooks to run multiple, complex tasks against a set of targeted hosts in an easily repeatable manner. A play is an ordered set of tasks run against hosts selected from your inventory.

The playbook is the core component of any Ansible configuration.

An Ansible playbook contains one or multiple plays, each of which define the work to be done for a configuration on a managed server. Ansible plays are written in YAML. Every play is created by an administrator with environment-specific parameters for the target machines; there are no standard plays.

Ansible plays are flexible due to modules, which pertain to various aspects of the target managed servers. The module script written in Ruby. Modules exist for many parts of system configuration, including software installation and user management. Ansible, a RED HAT company, provides many modules, as does the open source community that uses and supports Ansible.

The playbook is therefore composed of plays, which are composed of modules. It executes when the administrator runs the ansible-playbook command against target machines. The administrator must use an inventory file to specify the hosts under the playbook’s management.


The inventory file contains a list of all hosts that are managed by Ansible, and it offers an option to group hosts according to their functionality. For example, an administrator can apply a play to a group of web servers in the playbook, and a different play to a group of database servers.


If you are interested in ansible and or a Linux system administrator , chances are you’ve heard of Docker. If not, this software solution will make your life easier beginning today by helping you reduce operating costs and accelerate deployments — among other benefits.

But it’s not magic. Docker as a platform leverages containers — packages of an application along with all the tools it needs to run to eliminate differences between environments

DOCKER is computer software used for Virtualization in order to have multiple Operating systems running on the same host. Unlike Hypervisors which are used for creating VM (Virtual machines), virtualization in Docker is performed on system-level in so-called Docker containers.

You can see the difference in the image below, Docker containers run on top of the host’s Operation system. This helps you to improves efficiency and security. Moreover, we can run more containers on the same infrastructure than we can run Virtual machines because containers use fewer resources.

Unlike the VMs which can communicate with the hardware of the host (ex: Ethernet adapter to create more virtual adapters) Docker containers run in an isolated environment on top of the host’s OS. Even if your host runs Windows OS, you can have Linux images running in containers with the help of Hyper-V, which automatically creates small VM to virtualize the system’s base image, in this case, Linux.

Let’s see how to Configure Apache Web Server on Docker Container using Ansible :

One of the amazing things about the Docker ecosystem is that there are tens of standard containers that you can easily download and use.

In the following example we will instantiate an Apache Server container named web1. We will use an image called httpd:latest from Docker Hub. So that if requests made to our public IP address of Controller node on port 8080, it’ll be redirected to port 80 on the container. Also, instead of serving content from the container itself, we will serve a simple web page from /website of Controller node.

For this, we need to do following simple Steps:

  1. Create folder for Mounting dvd
  2. Mount dvd
  3. Create yum repository
  4. Install docker-ce
  5. Install Docker SDK
  6. Start and enable docker services
  7. pull httpd server image from dockerhub
  8. run the docker container and expose it to the public
  9. copy the html code in /var/www/html and start webserver

Now this is the code written in YAML format in Playbook :

And this is my file written in simple HTML code that I copied using

copy module. File name — myweb.html

After running the playbook, you can see these outputs. Here you can

see no red colored output came up that means there’s no error.

In Managed node we can check:

Here you can see, docker-ce has been installed.

We can check the service using “systemctl” command. Here for docker, it’s started

Using “Docker images” command, you can check the list of images in docker. Here httpd image of latest version is present.

Using “docker ps” command, you can check the containers running in docker.

Here you can see, httpd image with image name — web1 is running on port number 8082.

To check if our code is working properly or now, we can check on

So by searching for my ip address of Managed node on port number
8082 as mentioned in playbook, we can check :

Here you can see, webpage come up, as written in HTML code.
That means our webserver is working properly.

I hope now you have an idea about Ansible to get it started. Ansible is game changer in how you manage the infrastructure.

You can automate docker also using ansible. In one click, we can set up docker container and deploy httpd into it and start our webservice.
it’s Amazing !!!!

Hope you liked my blog and it would be useful for you :)