Introduction
Currently, Linux system management requires tools to automate repetitive tasks, ensure consistency of configurations and reduce deployment time. Ansible has been placed as one of the most popular solutions thanks to its simplicity, its non-agent architecture and its ability to manage both small and large-scale infrastructure. In this article we will explore what Ansible is, how it works and why it has become an indispensable ally for DevOps administrators and teams working with Linux environments.
What is Ansible?
Ansible is an open source automation tool that allows you to define configurations, deploy applications and orchestrate tasks using a YAML-based declarative language. Its architecture operates on SSH, which eliminates the need to install agents in managed nodes. Each machine only needs to have an SSH and Python service available, which facilitates its adoption in various Linux distributions.
Key features
- Agent-less: does not require daemons or additional services on nodes.
- Idempotency: running a playbook several times produces the same final state.
- Legible YAML language: playbooks are easy to read and write.
- Wide library of modules: more than 3000 official modules to manage packages, services, files, networks and clouds.
- Scalability: from one server to thousands of nodes by dynamic inventories.
Advantages to other tools
Compared to alternatives such as Chef, Puppet or SaltStack, Ansible stands out for its lower learning curve. There is no need to know a complex programming language; it is enough to understand YAML and the basic concepts of SSH. In addition, by not requiring agents, the maintenance overload is reduced and conflicts of versions in the nodes are avoided. The active community and extensive documentation make problem solving easier.
How to install Ansible in Linux
The installation varies slightly according to distribution, but in most cases the official package manager can be used. In Ubuntu or Debian, the command is:
sudo apt up
In CentOS, RHEL or Fedora dnf or yum is used:
Sudo dnf install - and ansible # Fedorasudo yum install - and ansible # CentOS 7
After installation, you can check the version withansible --versionand check connectivity by ping to the hosts defined in the inventory.
Structure of a playbook
A playbook is a YAML file that contains one or more plays. Each play defines a set of tasks that will be executed on a specified group of hosts. The basic syntax includes:
- hosts:indicates the target machine group or pattern.
- become:(optional) allows to raise privileges with sudo.
- tasks:task list, each calling a module with its parameters.
A simple example of structure is shown below:
---- hosts: webservers become: yes tasks: - name: Install Apache apt: name: apache2 state: present - name: Copy copy configuration file: src: files / httpd.conf dest: / etc / apache2 / apache2.conf owner: root group: root mode: '0644'
Practical example: setting up a web server
Suppose we want to deploy a Nginx server to all the group hostswebservers. The following playbook illustrates the complete process:
---- hosts: webservers become: yes vars: nginx _ version: 1.24 tasks: - name: Install Nginx from the official repository apt: name: nginx state: present update _ cache: yes - name: Make sure the service is active and enabled service: name: nginx state: started enabled: yes - name: Deloy from a copy: content: "Welcome to {{inventory _ hostname}}
"dest: / var / www / html / index.html owner: www-data group: www-data mode: '0644'
Good practices
- Use environment-separate inventories (development, staging, production) and avoid mixing credentials in the same file.
- Take advantage of the use of variables and files
vars/orgroup_vars/to keep playbooks clean and reusable. - Documenting each role and task with clear comments; this facilitates maintenance in large equipment.
- Test playbooks in test environments before applying them to production, using tools like
ansible-playbook --checkoransible-lint. - Keep the modules and Ansible version up to date to benefit from security and performance improvements.
Conclusion
Ansible has been consolidated as an essential tool for the automation of Linux infrastructure, thanks to its agent-less approach, its legible syntax and its wide ecosystem of modules. By adopting Ansible, teams can reduce human errors, accelerate deployments and achieve greater consistency in their environments. Whether you manage a few servers or a farm of thousands of nodes, Ansible offers the flexibility and power to meet the challenges of modern administration.


