Agree. So when targeting hosts we can use the inventory as environment and –limit to restrict to a specific group in this environment.
$ ansible-playbook -i inventory/stage -l dbservers
But what about vars? Both vars in group_vars/stage and group_vars/dbservers would apply for these hosts. But I can’t see a way to set a value for dbservers in stage and another for dbservers in production. Most cases could be addressed without this level of granularity, but I would like to know if there’s some way to achieve this.
And which one takes precedence? I assume groups are sorted alphabetically (are they?) so we should use some naming trick to guarantee that environments vars are consistently selected after (or before) “regular groups” vars.
$ python -c ‘import string ; print “”.join(sorted(string.printable))’
!"#$%&'()*+,-./0123456789:;<=>?@
ABCDEFGHIJKLMNOPQRSTUVWXYZ^_`abcdefghijklmnopqrstuvwxyz{|}~
Prepending ~ to environment names sounds like a good way to give them less weight than “regular groups”.