Hi all, just wanted to write about a fix/change I’ll be merging into the devel branch soon (ie. as soon as the AWS outage quits impacting our testing infrastructure), which means it will be included in the 2.3.0 release.
Per our variable precedence docs (http://docs.ansible.com/ansible/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable), the variables provided by the inventory script or INI file are supposed to be lower priority than those found in group_vars and host_vars files, however this has not been the case in 2.0 and it has gone unnoticed thus far.
While fixing this to match our documentation however, we realized that the precedence docs had a problem - variables defined on the host in the script/INI file would in fact have lower precedence than those in group_vars/all (or any group_vars files). We’ve decided to fix this based on the following rules for inventory:
- Host Vars > Group Vars
- Things relative to the playbook > Things relative to the inventory > Things defined in inventory
For those who are unfamiliar with the second point above, it is possible to have host/group vars files defined relative to both the playbook and to the inventory. For example, if you have:
playbook/site.yml
playbook/group_vars/all
inventory/hosts
inventory/group_vars/all
And you run:
$ ansible-playbook -i inventory/hosts playbook/site.yml
the variables in playbook/group_vars/all will “win” over those in inventory/group_vars/all.
Prior to this change, if you had something like:
ansible_connection: local
In any group_vars/all file, it would have “won” over anything defined in the inventory script, even if you did something like:
myhost ansible_connection=paramiko
the value in the group_vars would have been the value used, which is counter-intuitive.
If anyone has any questions regarding this change, please let us know.
Thanks!