Skip to content

Ansible Concepts

Ansible describes the desired state of systems in YAML playbooks and applies those playbooks from a control node.

Core Terms

  • Control node: the machine where Ansible runs.
  • Inventory: the list of hosts and host groups being managed.
  • Playbook: a YAML file that defines one or more plays.
  • Play: a set of tasks executed against a target group.
  • Task: one automation step, such as installing a package.
  • Module: the implementation behind a task.
  • Role: a reusable structure for playbooks, templates, variables, and handlers.
  • Facts: system information collected from managed hosts.
  • Handler: a task that runs when notified by another task.

Execution Model

Ansible usually connects over SSH, sends the module logic to the remote host, and executes it there. That makes it practical for orchestration and configuration without requiring long-running agents.

Why It Works Well

  • Tasks are usually idempotent.
  • Inventory and variables stay separate from task logic.
  • Playbooks are easy to read and review.
  • Roles make large automation codebases manageable.

Example Structure

- hosts: web
  become: true
  tasks:
    - name: Install nginx
      ansible.builtin.package:
        name: nginx
        state: present

Practical Notes

  • Keep your playbooks small and composable.
  • Use roles once the same pattern appears more than once.
  • Treat variables as part of the contract, not hidden implementation detail.