ansible/ansible — pull request #6666 by eggsby (2014-03-25 00:57:43+00:00)
Title: Use host-pattern for inventory var resolution

Fixes unintuitive behavior described in https://github.com/ansible/ansible/issues/6538

Prior behavior was to flatten variables by hostname. This meant that if a var was declared in multiple groups on a single host you would not be able to know which value of the var ansible would use.

This pull request utilizes the host pattern to prioritize the vars in matching hostgroups over non-matching hostgroups. This reduces ambiguous/undefined behavior in favor of an intuitive resolution order.

Prior resolution order was:

1. flattened vars from host class
2. vars from plugins
3. host vars from parser

This commit changes the resolution order:

1. flattened vars from host class
2. group vars from pattern :sparkles: __*new step*__ :sparkles:
3. vars from plugins
4. host vars from parser

In my local tests everything is completely backwards compatible, and we are using this fix in production currently. The use case in #6538 also works.

Thanks, let me know what I can do to help to get this merged,

Thomas Omans
Commission Junction