Ansible basics

Ansible Architecture

The above diagram illustrate Ansible architecture . The beauty of ansible is agentless . By default it manages remote connections over SSH (Linux & Unix) or WinRM (windows).

The “Ansible Automation Engine” consists of below core components.

Core component:

*Host Inventory




Now lets see each component functionality.

Host Inventory:

Inventory is a collection of hosts or nodes .A file that contains information about all the target server IP address and hostname that you are going to manage.

Inventory can be static (plain text or ini) or dynamic (.json) . You can make a goup within the inventory resources.

Default location of Inventory file is: /etc/ansible/hosts

Below is an example for static inventory:


 [dbservers] localhost


Unit of codes that ansible executes.  Each module has a particular use . Ex to install httpd package on centos you can use yum module . To manage the file content you can use file module

A python code invoked from tasks and executed on target hosts.  A playbook contains plays, a play contains different tasks, and a task includes modules.

Ansible has multiple 500+ built in modules . Also you can write your own custom modules if required .

Ansible works by connecting to your nodes and pushing out scripts called “Ansible modules” to them. Most modules accept parameters that describe the desired state of the system. Ansible then executes these modules (over SSH by default), and removes them when finished

Module Example:
* Cloud , Containers , Packaging, Files, Database, system,Network, Monitoring etc.


A playbooks is a file that defines the desired state of your system.

Defines list of tasks and they are written in YAML format , a data serialization language. Playbooks can include variables as well as tasks.

A playbook contains plays, a play contains different tasks, and a task includes modules. The tasks gets executed against a list of hosts in the same order that you have written them .

Sample Playbook

- name: Network Getting Started First Playbook
  connection: network_cli
  gather_facts: false
  hosts: all

    - name: Get config for VyOS devices
        gather_subset: all

    - name: Display the config
        msg: "The hostname is {{ ansible_net_hostname }} and the OS is {{ ansible_net_version }}"


Plugins are special kind of modules . Plugins are pieces of code that augment Ansible’s core functionality . plugins execute on the control node within the /usr/bin/ansible process for logging ,transforming output etc. These plugins get executed before a module is getting executed on the nodes.

Ansible ships with a number of handy plugins .

Action plugins – are front ends to modules and can execute tasks on the controller before calling the modules themselves.

Callback plugins – enable you to hook into Ansible events for display or logging purposes.

Cache plugins – are used to keep a cache of ‘facts’ to avoid costly fact-gathering operations.


Leave a Reply

Your email address will not be published. Required fields are marked *