Variables
Cheat sheet · https://pcornel.dk/topic.php?topic=5403
Answer
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.
Remember
- 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.
First checks
ansible-inventory --host <h>— effective varsansible <h> -m debug -a 'var=<var>'— value- Variable precedence doc — 22 levels
Verify in this order
sources by precedence → effective value
Where it usually breaks
Finding a variable declaration proves only one candidate source; the effective runtime value is proven at the consumption context after precedence and templating.
Inventory/vars → play/task selection → connection/become → module request → module result → target object read-back → handler/service effective state → workload verification. Preserve at least three independent checks: prerequisite/interface or identity/transport state; the owning control/service/policy state; then effective data-plane, backend or workload state. A healthy upstream boundary does not prove the downstream consumer or return path.
Variables Ansible boundary map
| 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 |
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5403