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.
https://docs.ansible.com/ansible/latest/reference_appendices/general_precedence.html
What is the order of precedence for Ansible variables?
1. Extra vars
(from command-line) always win.
2. Task vars
(only for the specific task).
3. Block vars
(only for the tasks within the block).
4. Role and include vars
.
5. Vars created with set_fact
.
6. Vars created with the register
task directive.
7. Play vars_files
.
8. Play vars_prompt
.
9. Play vars
.
10. Host facts.
11. Playbook host_vars
.
12. Playbook group_vars
.
13. Inventory host_vars
.
14. Inventory group_vars
.
15. Inventory vars
.
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.
Leave a Reply