For fun and profit


Ansible basics


También puedes leer este apunte en castellano pulsando aquí.

Ansible is a free software platform for configuring and managing computers. Based on Python, it allows to connect in parallel to multiple servers (via SSH), and implement in them the configurations that we have defined.

What can we do with Ansible?

In summary, anything that can be done from a shell script executed by SSH. Keep in mind that Ansible will not work well if we have to wait for you to ask us to send the information (for example with the passwd command).

How does it work?

To work, Ansible needs 4 things:

For example, we can use Ansible to manage the servers web1, web2 and mail1, create the web group for the web1 and web2 servers, and the mail group for the mail1 server, and then create a list of tasks such that:

If tomorrow we add a new mail server, add it to the mail group and run Ansible again, the same configuration will be installed as on the mail1 server. We can also define variables to install a different version of PHP on the server web2

If this example seems easy, understand Ansible is reduced to understand their names:

Where can I find Ansible roles?

Ansible offers Ansible Galaxy, a repository of roles ansible where anyone can bring the roles you have created, where we can find roles for practically any type of task that we want to carry out.

If we want to install a role, we will only have to execute the ansible-galaxy command. For example, to install an ntp server, we could execute:

  ansible-galaxy install geerlingguy.ntp

Template to start with Ansible

To be able to start working with Ansible, I have created a pre-configured and documented Ansible template, with which you can start working in a matter of minutes.

You can find it at: