Variable Precedence Calculator
Determine which Ansible variable source wins based on precedence order rules.
About Variable Precedence Calculator
Ansible resolves the same variable name defined in multiple places using a strict, well-documented 22-level precedence order, from role defaults (lowest) to extra vars passed with -e on the command line (highest, always wins). This calculator looks up two variable sources and reports which one wins based on their rank in that order — higher rank always overrides lower rank regardless of where the variable 'looks' like it should apply.
Formula
winner = source with max(rank_A, rank_B) in Ansible's 22-level precedence order
- rank_A
- Precedence level of source A (1-22)
- rank_B
- Precedence level of source B (1-22)
Worked example
With the default values below, Variable Precedence Calculator returns Winning Variable Source of extra vars (always win, e.g. -e in CLI). Change any input above and every figure here is recalculated in your browser.
Inputs used
- Variable Source Aone of 1. command line values (e.g. -e), 2. role defaults (defined in role/defaults/main.yml), 3. inventory file or script group vars, 4. inventory group_vars/all, 5. playbook group_vars/all, 6. inventory group_vars/*, 7. playbook group_vars/*, 8. inventory file or script host vars, 9. inventory host_vars/*, 10. playbook host_vars/*, 11. host facts / cached set_facts, 12. play vars, 13. play vars_prompt, 14. play vars_files, 15. role vars (defined in role/vars/main.yml), 16. block vars (only for tasks in block), 17. task vars (only for the task), 18. include_vars, 19. set_facts / registered vars, 20. role (and include_role) params, 21. include params, 22. extra vars (always win, e.g. -e in CLI)
- 2. role defaults (defined in role/defaults/main.yml)
- Variable Source Bone of 1. command line values (e.g. -e), 2. role defaults (defined in role/defaults/main.yml), 3. inventory file or script group vars, 4. inventory group_vars/all, 5. playbook group_vars/all, 6. inventory group_vars/*, 7. playbook group_vars/*, 8. inventory file or script host vars, 9. inventory host_vars/*, 10. playbook host_vars/*, 11. host facts / cached set_facts, 12. play vars, 13. play vars_prompt, 14. play vars_files, 15. role vars (defined in role/vars/main.yml), 16. block vars (only for tasks in block), 17. task vars (only for the task), 18. include_vars, 19. set_facts / registered vars, 20. role (and include_role) params, 21. include params, 22. extra vars (always win, e.g. -e in CLI)
- 22. extra vars (always win, e.g. -e in CLI)
Results
- Winning Variable Source
- extra vars (always win, e.g. -e in CLI)
- Winning Precedence Level
- 22 of 22
- Precedence Gap Between Sources
- 20 levels
Step by step
- 1Source A precedence rank= Level 2 of 22
- 2Source B precedence rank= Level 22 of 22
- 3Higher rank wins= Source B wins (level 22)
Assumptions and limits
- The result is derived only from the 2 inputs listed above. Anything not among them is not part of the calculation.
- In particular, this calculator does not take inflation, tax, fees or charges or compounding frequency into account.
- Figures are rounded for display to whole numbers, so totals built from several rounded parts can differ slightly from the unrounded arithmetic.
How these calculators are built and tested is described on the Methodology page. If a figure looks wrong, please report it.
Frequently Asked Questions
What always wins regardless of anything else?
Extra vars passed via `-e` on the `ansible-playbook` command line (level 22) always have the highest precedence and cannot be overridden by any other source, including task vars.
Why do role defaults have the lowest precedence?
Role defaults are designed to be easily overridden — they exist to provide sane fallback values, not to enforce behavior, so nearly every other variable source can override them.
Do task vars beat role vars?
Yes — task vars (level 17) are more specific in scope than role vars (level 15) and win, which follows Ansible's general principle that more specific/local scope beats broader/less specific scope.
Where can I see the official precedence order?
The Ansible documentation's 'Understanding variable precedence' page lists the canonical 22-level order this calculator implements verbatim.
