Function get_group_variables() not working?

It looks like the function get_group_variables() isn’t working. Here is some example code:

from ansible import inventory

inventory_manager = inventory.Inventory(options.inventory)
hv = inventory_manager.get_variables(‘hostname’)
gv = inventory_manager.get_group_variables(‘groupname’)

“hv” is getting a dictionary with all the variables but “gv” is always empty. Is that a bug or a feature?

I’d suggest taking a look about how it is being used in core Ansible code, but I’m also wondering if there isn’t an inventory configuration to debug first…

Can you share details of your inventory?

–Michael

It seems that the function is never used in Core.

So I’ve created an inventory and posted that to https://gist.github.com/jurgenhaas/11136532 (the directory structure is broken: there is a hosts and a test.py in the root, and a couple of files in subdirectories group_vars and host_vars). test.py is taken from original ansible script and a couple of lines added at the end to grab and print variables.

When you then run ./test.py all -i ./hosts -m setup you get empty variables for the group and all the variables for the host. I think that demonstrates the problem.

Hi,

I can confirm Inventory.get_group_variables(‘groupname’) doesn’t do anything usefull currently, it just calls for group.get_variables() - which basically return groups.vars - and caches it’s results, but groups.vars never gets any data filled in (at least not with ini files, it is used I believe with scripts).

Keep in mind that host and groups vars are data that is parsed by the group vars plugins, and as such is technically not a direct part of the inventory itself, as they are picked up late by runner calls, and per host, not per group.

This is one of the things that is addressed by my PR “vars_plugins refactor and move into core inventory #6734” (https://github.com/ansible/ansible/pull/6734)
​​

Serge

Sounds good and I hope your PR makes it into core soon.

Yep, we’re currently attacking the “P2” ticket queue, once this gets reduced to 0 we’ll see about testing all of this out. I’m interested in this very much as well, though the consequences of merging this close to release are a little dangerous (as I would say this of any large patch set, not singling out this one).

​I definitely agree. I looked at lots of use cases and lots of tests, and
even then I - later - encountered lots of other cases. I'm pretty sure
there still will be corner cases to roughen out when testing at large.​