It’s been a long time since I read this entry by Raúl Hernández González, and he has come back to me on many occasions. I...
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:
- A list of servers that we are going to work with
- Create groups with those servers (to facilitate the work)
- A series of tasks to do (for example , install nginx + PHP)
- Define a list of tasks for a series of groups
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:
- On the servers of the web group, install nginx + PHP 7
- On the mail group servers, install exim with DKIM support
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:
- servers: inventory/hosts
- server group:  in inventory/hosts
- variables: inventory/host_vars and inventory/group_vars
- tasks: roles
- task lists: playbooks
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: