Ansible Precedence Order
Ansible variable precedence, sometimes also referred to as variable priority or hierarchy, determines which value will be assigned to a variable when that variable is defined in multiple places. The general principle is that the more specific declarations will override the more general ones.
What is the order of precedence for Ansible variables?
vars (from command-line) always win.
vars (only for the specific task).
vars (only for the tasks within the block).
4. Role and include
5. Vars created with
6. Vars created with the
register task directive.
10. Host facts.
16. Role defaults.
What is the highest variable precedence in Ansible?
Ansible documentation states that the command line has the highest precedence this will override any variable defined anywhere else.