Understanding variable precedence
Ansible does apply variable precedence, and you might have a use for it. Here is the order of precedence from least to greatest (the last listed variables override all other variables):
In general, Ansible gives precedence to variables that were defined more recently, more actively, and with more explicit scope. Variables in the defaults folder inside a role are easily overridden. Anything in the vars directory of the role overrides previous versions of that variable in the namespace. Host or inventory variables override role defaults, but explicit includes such as the vars directory or aninclude_varstask override inventory variables.
Ansible merges different variables set in inventory so that more specific settings override more generic settings. For example,ansible_ssh_userspecified as a group_var is overridden byansible_userspecified as a host_var. For details about the precedence of variables set in inventory, seeHow variables are merged.
Footnotes
The previous text describes the default confighash_behavior=replace. Switch tomergeto overwrite only partially.