Pcornel
Browse topics
Options
Recent
Favorites
Automation · Technical reference

Roles · Ansible

Direct answer

Ansible roles organize reusable tasks, handlers, defaults, variables, templates, files and metadata into a conventional content unit that can be included across plays.

When to use this

Use it when configuring, checking or troubleshooting Roles in Ansible.

First 30 seconds

1. Roles: tasks, handlers, templates, files, defaults, vars, meta.

2. Single responsibility.

3. Argument specs validate inputs.

4. Test with Molecule.

5. Version roles.

Operational verification

role → reusable tasks → hosts

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
Ansible automation
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformAnsible automation · Roles owns Ansible role composition/reuse. Collections/Galaxy own distribution; target domains own managed technologies.
Scope / prerequisiteUse it when configuring, checking or troubleshooting Roles in Ansible.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

4 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Operational evidence path Verify boundary

role source/version → defaults/vars/params → dependencies/entry point → selected tasks/handlers/templates → target state → rerun

Healthy evidence: role version and inputs are explicit, selected content is traceable, dependencies are understood and target state/rerun match intent.

Step 2 Failure modes and next checks Narrow the fault

Suspicious evidence: shadowed variables, unexpected role entry point, hidden dependency, incompatible platform assumption or treating role inclusion as convergence evidence.

Step 3 Common mistakes Narrow the fault
  • Roles with hard-coded values instead of defaults.
  • Roles depending on variables defined elsewhere without documentation.
Step 4 Where it fails Narrow the fault

Where Roles usually goes wrong: role identity/version, defaults/vars/tasks/handlers composition, dependency ordering and reuse boundaries.

Evidence references

Evidence · 1 on this Topic

Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.

observation · 1
Key points
  • Role included ≠ all role content runs; entry points, tags and conditionals can select subsets.
  • Role defaults ≠ final variable values; they have deliberately low precedence.
  • Role dependency declared ≠ external prerequisite healthy; dependency execution and target state still require evidence.
  • Reusable role ≠ universally safe; platform and variable assumptions can remain implicit.
Key checks
  • ansible-galaxy role init roles/<name> — structure
  • molecule test — role tests
  • meta/argument_specs.yml — input validation
ReferenceWhat it is1 section · depth on demand

Core model

Trace role source/version, entry point, defaults versus vars precedence, dependencies, task/handler inclusion and role parameterization before troubleshooting behavior.

ReferenceImportant terms & boundaries2 sections · depth on demand

What this shows and what it does not

A role loading successfully shows reusable content resolved, but it does not show all assumptions, dependencies or target outcomes are satisfied.

In depth

An Ansible role packages tasks, handlers, templates, files, defaults and metadata in a standard directory layout so the same functionality can be reused across playbooks and shared.

roles/ntp/
  defaults/main.yml   # lowest-precedence variables
  tasks/main.yml
  handlers/main.yml
  templates/chrony.conf.j2
  meta/main.yml

Documented example, not captured output.

Put overridable settings in defaults, keep roles focused on one service, and test them with Molecule. Collections can bundle several roles with modules for distribution.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor docAnsible automation current

Authoritative/upstream documentation reviewed for bounded claims in Ansible > Roles. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://docs.ansible.com/ansible/latest/ · confidence 94%
Terminology layer

Terms & aliases

Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.

Aliases that resolve here
ansible roleroles directoryrole defaultsrole dependencies
Embedded reference data

Quick lookup tables

Roles Ansible boundary map

Fast input/selection, execution/result and target-proof boundaries for Roles.

BoundaryHealthy evidenceSuspicious evidence
Inputs / selectionCorrect inventory, hosts, variables/facts and content are explicitWrong scope, stale facts, hidden precedence or content-version drift
ExecutionConnection, privilege, module/task context and ordering match intentUnreachable, wrong execution host, privilege/plugin failure or misleading skip/change state
Result semanticsPer-host/item results are preserved and interpreted correctlyAggregate recap hides partial/skipped/handled failures
Target proofResource/workload read-back and rerun confirm convergenceGreen Ansible status treated as end-to-end acceptance
Depth when you need it

Deep reference

Healthy vs suspicious evidence

Output interpretation

For Roles, rely on structured fields and stable IDs (role identity/version, defaults/vars/tasks/handlers composition, dependency ordering and reuse boundaries) rather than text formatted for display.

Confirmation

Confirm action

Continue?