dynamic inventory, group vars and role vars precedence

Hello Ansiblers,

This is about two different things (I know, bad!), but all about variables. This is on Ansible 1.7.2.
I’ve put up my test code on https://github.com/mguillaume/ansible-vars-test for easy review/reproducing.

First, unless I messed up somewhere, it seems hosts dynamically added to a group still don’t pick up the correct group_vars (supposed to have been fixed for https://github.com/ansible/ansible/issues/8605 )
→ See test 1&2

Second, it seems role variables take precedence over group variables. Is that normal? I would have expected the opposite myself.
→ See test 3

Side note 1:
I’m using localhost for my host in the tests, could be there’s some specific code for it that makes things break.

Side note 2:
If I have localhost in group test in my hosts-static inventory file and run with ansible-playbook -i hosts-static,localhost , I end up with localhost not in group test.
Since I’ve seen elsewhere that running things this way was kinda hackish and not supported this may just be something that doesn’t need to be fixed.

Any insight welcome :slight_smile:

First, unless I messed up somewhere, it seems hosts dynamically added to a
group still don't pick up the correct group_vars (supposed to have been
fixed for https://github.com/ansible/ansible/issues/8605 )
-> See test 1&2

​There have been so​me patches in that area. Could you check if that is
still a rpoblem in 1.8 devel?

Second, it seems role variables take precedence over group variables. Is
that normal? I would have expected the opposite myself.
-> See test 3

​role/vars​

​take precedence over inventory vars yes.​ to avoid that, consider using
role/defaults

Side note 1:
I'm using localhost for my host in the tests, could be there's some
specific code for it that makes things break.

​localhot is something special, so yes, that is possible; try testing with
a "remote host" (which you can access -c local)​

​but test avoiding using the name localhost or the loopback ip ​

Side note 2:
If I have localhost in group test in my hosts-static inventory file and
run with ansible-playbook -i hosts-static,localhost , I end up with
localhost not in group test.
Since I've seen elsewhere that running things this way was kinda hackish
and not supported this may just be something that doesn't need to be fixed.

​Yes. Hackish things are special :slight_smile:

Working good in 1.8 devel.