Skip to main content

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:

ComponentPurpose
ControllerRuns Ansible commands and playbooks.
Managed nodesRemote machines configured by the controller.
InventoryLists hosts and groups that Ansible can target.
ModulePerforms a specific action on a managed node.
PlaybookDefines automation steps in YAML.
RolePackages 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 ping module.
  • 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