Ansible role
A reusable package of tasks, handlers, templates, files and variables for one unit of automation, laid out in a standard directory structure.
In more detail
A play applies a role by listing it under roles, and can pass variables to customise it. The role owns its implementation, while the caller only chooses hosts and inputs, which lets several plays and projects share it. Document what the role guarantees after it runs; that contract guides its tasks and its tests.
Example
roles:
- role: web
vars:
site_name: Training siteRelated terms
- role directory structure — The fixed set of folders inside a role, such as tasks, handlers, templates, files, defaults and vars, each holding one kind of content.
- role defaults — The variables in a role's defaults/main.yml: safe starting values that callers are expected to override.
- play — One section of a playbook that picks a set of hosts with a pattern and lists the tasks to run on them, in order.
- Ansible Galaxy — The public online hub for sharing Ansible roles and collections, and the ansible-galaxy command that installs from it.
- Molecule — A testing framework for Ansible roles that creates a disposable test machine, applies the role, checks the result and destroys the machine.
Taught in
- Error Handling With Block, Rescue And Always — Ansible Configuration Management at Scale
- The Standard Directory Layout And Roles — Ansible Configuration Management at Scale
- Writing A Role — Ansible Configuration Management at Scale
- Using Collections — Ansible Configuration Management at Scale
- Ansible Galaxy — Ansible Configuration Management at Scale
- Testing With Molecule — Ansible Configuration Management at Scale
- Environment Specific Configuration — Ansible Configuration Management at Scale
- Exam Strategy: The First Fifteen Minutes And ansible-doc — RHCE in Ansible (EX294): Automate Red Hat Systems
- Inventory Variables: Ranges, group_vars And host_vars — RHCE in Ansible (EX294): Automate Red Hat Systems
- ansible.cfg: Which File Wins, And The Settings That Matter — RHCE in Ansible (EX294): Automate Red Hat Systems
- Finding Modules In Collections: ansible-doc And navigator — RHCE in Ansible (EX294): Automate Red Hat Systems
- Git And VS Code: Clone, Commit, Push, And The Dev Container — RHCE in Ansible (EX294): Automate Red Hat Systems
- Roles: The Directory Ansible Expects, Defaults And Handlers — RHCE in Ansible (EX294): Automate Red Hat Systems
- requirements.yml: Installing Roles And Collections — RHCE in Ansible (EX294): Automate Red Hat Systems
- RHEL System Roles: timesync And selinux From A Collection — RHCE in Ansible (EX294): Automate Red Hat Systems
- Ansible Vault: Secrets Encrypted, Runs Without A Prompt — RHCE in Ansible (EX294): Automate Red Hat Systems
- Mock Exam, Part 1: Seven Tasks Across Three Sections — RHCE in Ansible (EX294): Automate Red Hat Systems
- Mock Exam, Part 2: Real Machines And The Patterns That Fail — RHCE in Ansible (EX294): Automate Red Hat Systems