Use it when configuring, checking or troubleshooting Variables in Ansible.
Variables · Ansible
Ansible variables provide runtime data to plays, roles, tasks and templates, with scopes and a precedence model that can make the effective value differ from the nearest visible declaration.
1. Variables: defaults, group_vars, host_vars, play vars, extra vars (highest).
2. Use defaults for role inputs.
3. Avoid overriding with extra vars casually.
4. Clear names (role prefix).
5. Secrets in vault.
sources by precedence → effective value
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Operational evidence path Verify boundary
variable declarations/sources → precedence/scope → host context → Jinja/task argument resolution → action → target result
Healthy evidence: source and precedence are understood, effective value/type is verified in the failing context and target behavior matches the corrected input.
Step 2 Failure modes and next checks Narrow the fault
Suspicious evidence: duplicate names across layers, extra-var override, wrong type, host-specific divergence or debugging secrets by printing them indiscriminately.
Step 3 Common mistakes Narrow the fault
- Not knowing the variable precedence order.
- Overusing extra vars (
-e), which override everything.
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.
- Variable defined ≠ variable value used; higher-precedence sources can override it.
- Same name across hosts ≠ same value; host/group/fact/context can differ.
- String that looks boolean/number ≠ same data type; YAML/Jinja typing can change comparisons.
- Secret variable hidden in output ≠ securely sourced or least-privileged.
ansible-inventory --host <h>— effective varsansible <h> -m debug -a 'var=<var>'— value- Variable precedence doc — 22 levels
ReferenceWhat it is1 section · depth on demand
Core model
Debug variables by name, type, source, scope, host context and precedence; resolve the effective value at the point of use instead of searching only for text definitions.
ReferenceImportant terms & boundaries2 sections · depth on demand
What this shows and what it does not
Finding a variable declaration shows only one candidate source; the effective runtime value is confirmed at the consumption context after precedence and templating.
In depth
Ansible variables customise playbooks per host, group or run. They come from many places, and a fixed precedence order decides which value wins — a common source of surprises.
| Source (low → high precedence, simplified) |
|---|
| Role defaults |
Inventory group_vars/all, then other groups, then host_vars |
Play vars and vars_files |
Role vars |
set_fact / registered vars |
Extra vars (-e) — always win |
ansible -i inventory/ sw01 -m ansible.builtin.debug -a 'var=ntp_servers'
Keep each variable defined in as few places as possible and document where.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Ansible > Variables. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://docs.ansible.com/ansible/latest/ · confidence 94%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.
Quick lookup tables
Variables Ansible boundary map
Fast input/selection, execution/result and target-proof boundaries for Variables.
| Boundary | Healthy evidence | Suspicious evidence |
|---|---|---|
| Inputs / selection | Correct inventory, hosts, variables/facts and content are explicit | Wrong scope, stale facts, hidden precedence or content-version drift |
| Execution | Connection, privilege, module/task context and ordering match intent | Unreachable, wrong execution host, privilege/plugin failure or misleading skip/change state |
| Result semantics | Per-host/item results are preserved and interpreted correctly | Aggregate recap hides partial/skipped/handled failures |
| Target proof | Resource/workload read-back and rerun confirm convergence | Green Ansible status treated as end-to-end acceptance |