Ansible
Updated Dec 01, 2020 ·
Overview
Ansible is an automation tool used to configure servers, deploy applications, and run repeatable operations across managed hosts.
The main pieces are:
| Component | Purpose |
|---|---|
| Controller | Runs Ansible commands and playbooks. |
| Managed nodes | Remote machines configured by the controller. |
| Inventory | Lists hosts and groups that Ansible can target. |
| Module | Performs a specific action on a managed node. |
| Playbook | Defines automation steps in YAML. |
| Role | Packages tasks, variables, files, handlers, and defaults. |
Note: Older notes may use master, node, host, or managed host. In these notes, those terms map to the controller and managed nodes.
Learning Path
Start with the core workflow:
- Install Ansible on the controller.
- Create an inventory for the target hosts.
- Confirm SSH trust between the controller and managed nodes.
- Test connectivity with the
pingmodule. - Run ad hoc commands for simple tasks.
- Convert repeated commands into playbooks.
- Move repeated playbook patterns into roles.
Install Ansible
Install Ansible on the controller machine.
# RHEL, CentOS, Fedora
sudo dnf install ansible -y
# Debian and Ubuntu
sudo apt install ansible -y
Check the installed version.
ansible --version
First Commands
List hosts from the active inventory.
ansible --list-hosts all
List hosts from a custom inventory.
ansible -i inventories/edendev.inv --list-hosts all
Test connectivity.
ansible all -m ping
Run a command on a group.
ansible webservers -m command -a "uptime"
Documentation
Use ansible-doc to inspect modules from the command line.
ansible-doc -l
ansible-doc ping
ansible-doc copy