Default Image

Months format

View all

Load More

Related Posts Widget

Article Navigation

Contact Us Form


Sorry, the page you were looking for in this blog does not exist. Back Home

Breaking Tech News

An Overview of Ansible

By reading this article, you can understand an overview of ansible. What is it? Why we need it? Moreover its concepts.

What is Ansible?

Ansible is software mostly used for software configuration management (SCM), DevOps automation, and orchestration. Ansible simplifies the IT Operations in On-premises and multi-cloud environments so that System admins are love this tool to use because of simple installation and easy-to-understand concepts and play with YAML files.

Why we need Ansible?

  • Ansible is an Open source
  • Ansible is very lightweight and no constraints regarding the operating system or underlying hardware are present
  • Highly secure because of agentless and also ansible server communicating with clients by SSH
  • Ease to understand the concepts by official documentation. No need for any additional skills except system administration

Important Concepts of Ansible


Playbooks are written in YAML format and have a minimum of configuration syntax. These playbooks consist of configurations, administrations, deployments, systems, automation tasks, and other orchestrations functions.


An action will specify which of the modules to execute. A task must have only one action, but it may also have other parameters.


Playbooks used to execute tasks. The task consists of an action with a name and some other keywords. A list of tasks also called Tasks.


You can understand notify as an alert. Whenever we define a handler for multiple tasks should be done in order like one by one. If one task completed notify will trigger the next task or handler. The purpose of the handler will trigger the next task.


Handlers also called tasks, but handlers are a particular kind of task that does not execute unless notifying by name. Handlers mostly used for certain scenarios as if when we update an existing configuration and we need to restart the system or service, at that time we will use the handlers to trigger restart by notifying the restart action.


Inventory is a folder or file, which contains a list of Groups, and Hosts. In Inventory, we can define Hosts details like Hosts Name, IP, Domain name, etc.


A host is a remote machine or client managed by Ansible. Each host assigned by individual variables and organized into groups. These host details are written in the host_vars file in the inventory folder


A group consists of ‘n’ number hosts. Each group can have variables that can be applied to all hosts in the group. These group details are written in the group_vars file in the inventory folder


Consists of module collection are available in /usr/bin/ansible or an Ansible playbook.


A template is a file, which contains configuration parameters. Each template has dynamic values that are given as variables. This template used to copy data from the ansible controller to remote clients. This data generated by the jinja2 engine.


Ansible tags should execute only one or some specific tasks from a long playbook instead of executing the whole playbook.

Ad-hoc commands

Commands, which can execute directly from the terminal to manage the remote hosts.


Ansible Galaxy is an open-source and online repository for sharing and pulling ansible modules, roles, and other collections.

Ansible facts

This fact used to fetch information from remote hosts from the ansible controller, which is used to declare as variables in playbooks for identification remote hosts status.


The role is a combination of multiple tasks together into one container or unit to do automated tasks with clean directory structures.
  • We can modify roles easily.
  • By the help of roles, we can reduce the syntax errors.
  • Assigning a role to a group of hosts (clients) or a particular host (client) or user, which implies implementing a set of certain variable values, certain tasks, and certain handlers. Because of the directory structure associated with a role, roles become a redistributable container that allows us to share tasks among playbooks.


Modules are the set of functions that Ansible send to clients. Modules are stored in /usr/bin/ansible or /usr/bin/ansible-playbook.

The entire ansible directory structure consists of inventories, playbooks, roles.

Roles Directory Structure explained in detailed:

├── ansible.cfg  
├── inventories  
│   ├── development  
│   │   ├── group_vars  
│   │   │   └── development.yml  
│   │   ├── hosts  
│   │   └── host_vars  
│            └── development_server.yml  
│   └── production  
│       ├── group_vars  
│       │   └── production.yml  
│       ├── hosts  
│       └── host_vars  
│           └── production_server.yml  
├── playbooks  
     └── deployment.yml  
└── roles  
    └── apache  
        ├── defaults  
        │   └── main.yml  
        ├── files  
        ├── handlers  
        │   └── main.yml  
        ├── meta  
        │   └── main.yml  
        ├── tasks  
        │   └── main.yml  
        ├── templates  
        ├── tests  
        │   ├── inventory  
        │   └── test.yml  
        └── vars  
            └── main.yml  

Example role: - to install apache software in hosts so created role as apache and configured roles components.

Tasks - contains main tasks to execute by the role.

[root@gokul apache]# vi tasks/main.yml  
- name: Install httpd Package  
yum: name=httpd state=latest  
- name: Copy httpd configuration file  
copy: src=/data/httpd.original dest=/etc/httpd/conf/httpd.conf  
- name: Copy index.html file  
copy: src=/data/index.html dest=/var/www/html  
- restart apache  
- name: Start and Enable httpd service  
service: name=httpd state=restarted enabled=yes  

Files - contain files required to transfer or deployed to the target machines via this role.

Copy the required files (httpd.conf and index.html) to the files directory

[root@gokul apache]# ll files/*  
-rw-r--r-- 1 root root 11753 Feb 4 10:01 files/httpd.conf  
-rw-r--r-- 1 root root 66 Feb 4 10:02 files/index.html  
[root@gokul apache]# cat files/index.html 

Handlers - contain handlers, which may used by this role.

Edit handler’s main.yml to restart the server when there is a change

[root@gokul apache]# cat handlers/main.yml  
# handlers file for /etc/ansible/roles/apache  
- name: restart apache  
service: name=httpd state=restarted  
Defaults - contain default variables for the role.

Vars - other variables for the role. Vars have a higher priority than defaults.

Templates - contains templates, which can deploy via this role.

Meta - defines some data / information about this role.

Edit meta main.yml to add the information about the roles like author, descriptions, license,

platforms supported

root@gokul apache]# cat meta/main.yml  
description: Apache Webserver Role  
company: gokul  
# If the issue tracker for your role is not on github, uncomment the  
# next line and provide a value  
# issue_tracker_url:  
# Some suggested licenses:  
# - BSD (default)  
# - MIT  
# - GPLv2  
# - GPLv3  
# - Apache  
# - CC-BY  
license: license (GPLv2, CC-BY, etc)  
min_ansible_version: 1.2  
# If this a Container Enabled role, provide the minimum Ansible Container version.  
I hope, you can understand this ansible overview
please like and share
cheers, Gokulakrishna 


Tech Optimist, Senior Software Engineer, Blogger, Youtuber.

Post a Comment