Middle
Priority of variables in Ansible (host_vars, group_vars, extra_vars)
sobes.tech AI
Answer from AI
In Ansible, variables can be set in different places, and a certain priority is applied in case of conflicts. The main priority levels for variables (from lowest to highest) are:
- group_vars — variables defined for host groups.
- host_vars — variables defined for a specific host.
- extra_vars — variables passed via the command line using
-e.
Thus, if the same variable is defined in multiple places, the value with the higher priority will be used. For example, extra_vars will always override values from host_vars and group_vars.
This allows flexible configuration of playbooks and overriding values when necessary.