Automating Linux Administration with Ansible
Ansible Basics
What Is Ansible?
Ansible is an open-source tool that automates repetitive IT tasks. Think of it as a universal remote for your computers. Instead of logging into dozens or hundreds of servers to update an application or change a setting, you can tell Ansible to do it for you, all at once.
This process is broadly called configuration management. It ensures that all your systems are set up in a consistent, predictable way. Beyond that, Ansible is also used for deploying applications and automating complex workflows, like setting up a new server from scratch without manually typing a single command on it.
Ansible is designed to be minimal, consistent, secure, and highly reliable, with an extremely low learning curve for administrators, developers, and IT managers.
How Ansible Works
Ansible’s architecture is simple and straightforward. It operates on two types of computers: a control node and managed nodes.
- Control Node: This is the computer where Ansible is installed. You run your automation commands from here.
- Managed Nodes: These are the servers or devices that the control node manages. Ansible performs tasks on these nodes.
A single control node can manage hundreds of managed nodes, pushing out configurations and instructions to all of them simultaneously.
One of Ansible's most important features is its agentless design. Many other automation tools require you to install special software, called an agent, on every managed node. This agent runs in the background, waiting for instructions from a central server.
Ansible doesn't need this. It communicates with managed nodes using standard Secure Shell (SSH), a protocol that's already built into nearly every Linux, macOS, and Unix-like operating system. This makes setup much faster and simpler. There's no agent software to install, manage, or update on your fleet of servers, which reduces the security footprint and simplifies maintenance.
Because it's agentless, Ansible gets you started on automation right away. You don't need to bootstrap an entire infrastructure before you can manage it.
Getting Started with Installation
Ansible is designed to run on Linux or macOS, so your control node will need to be one of these operating systems. Windows users can set up a control node using the Windows Subsystem for Linux (WSL). Any machine can be a managed node, including Windows servers.
The installation process is straightforward using your system's package manager. Here are the commands for some of the most common operating systems.
# For Debian/Ubuntu
sudo apt update
sudo apt install ansible -y
# For RHEL/CentOS/Fedora
sudo dnf install ansible -y
# For macOS (using Homebrew)
brew install ansible
Once installed, you can verify it by running ansible --version.
The next step in configuring Ansible involves creating an inventory file. This is a simple text file that lists the IP addresses or hostnames of your managed nodes. Ansible reads this file to know which machines it should connect to and manage. We'll dive into creating inventories and running commands in the next section.