Variable Precedence Calculator
Look up Ansible's 22-level variable precedence order and see which source wins when a variable is defined in two places.
Inputs
First location the variable is defined.
Second location the same variable is defined.
Winning Variable Source
extra vars (always win, e.g. -e in CLI)
Winning Precedence Level
22of 22
Precedence Gap Between Sources
20levels
Step by step
Source A precedence rank
role defaults (defined in role/defaults/main.yml)
= Level 2 of 22
Source B precedence rank
extra vars (always win, e.g. -e in CLI)
= Level 22 of 22
Higher rank wins
max(2, 22)
= Source B wins (level 22)
How it works
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)
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.