Made $groups and $group_names variables accessible in with_items #1024

merged 2 commits into from Sep 11, 2012

2 participants


This patch is specifically for use in with_items: in a playbook as mentioned in the Advanced Playbooks docs for Jinja templates.


Seems like we could just make group_list call the keys() method on the result of getting the groups in, rather than duplicating the traversal logic?


Looking through the code I was under the impression that groups in there were not resolved to just host names. I'm mistaken?


If I have a host inventory:




From what I saw, if I just use the keys method and call groups['northeast'] I'd get newengland and midatlantic not Host1-4. From the code I found in the Host class that didn't seem like the correct answer especially because you can resolve a group inside another group. I was thinking about the MongoDB example as I went.

Hope that helps better explain what I was thinking.


Yeah makes sense, you're right.

Here's what I was talking about in Runner code that generates the variable that is made available in playbooks:

group_hosts = {}
for g in self.inventory.groups:
     group_hosts[] = [ for h in g.hosts ]
inject['groups'] = group_hosts

So yeah, from what you say, that won't contain ancestors -- and in that case, we must fix this as well, as part of this patch, so that it does.

Does that sort of make sense?


It does. I can make the change to the code above and resubmit this patch. Sound good?

@tima tima Made groups.groupname and group_names variables accessible in playbooks.
Also modified code that feeds the groups data structure to templates so
that it resolves groups inside of groups to hostnames.

OK. Resubmitted. That should do it.

@mpdehaan mpdehaan merged commit 58ad934 into ansible:devel Sep 11, 2012

merging, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment