Ansible 101 : A Brief introduction.


Ansible is an automation tool for a variety of IT tasks.
When we have hundreds of servers that would need regular backups, updates,.., the manual approach is not the best way.
For repetitive tasks, deployment of applications in a complex infrastructure we use Ansible.

Agentless approach:

With Ansible, there is no need to install agents or clients on the different machines and then update them regularly, we only need to install Ansible on the control machine.
Ansible pushes the "requests" from a control machine towards the hosts using ssh (Secure Shell) and retrieves the answer to to the control machine.

The configuration of Ansible lives in the "/etc/ansible/ansible.cfg" file, it contains information about the environmental variables, paths, SSH arguments, privileges,...

Ansible Yaml file (Playbook):

Ansible uses Yaml to configure the tasks to be executed on remote machines. Yaml is easy to read and uses indentation just like python to structure its instructions.

Ansible modules:

Ansible uses modules to execute specific tasks:

We can group modules together to be able to do more complex tasks.
Modules put together in a certain order are called a playbook.

Tasks and modules:

A task is a "wrapper" around an Ansible module, it contain the module and its arguments and other type of data related to that specific module.

Modules are programs that can be started from Yaml files.


The list of modules and their parameters are described in the Ansible documentation page.

The hosts file:

The "hosts" file contain an inventory of hosts involved in Ansible operations (/etc/ansible/hosts).
It looks like the below:

The play and the playbook:

A play defines the "tasks", the "hosts" on which the tasks are going to be executed, the "user" under which these tasks are going to run and other parameters.
One or more plays make up a playbook:

The "hosts: linux_machines" is described in the hosts file it consists of the below IP addresses:

Running the Yaml file:

To run the Yaml file containing the playbook, we use the below command:


Leave as a comment: