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

Merged
merged 2 commits into from Sep 11, 2012

2 participants

@tima

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

@mpdehaan

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

@tima

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

@mpdehaan
@tima

If I have a host inventory:

[newengland]
Host1
Host2

[midatlantic]
Host3
Host4

[northeast]
newengland
midatlantic

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.

@mpdehaan

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[g.name] = [ h.name 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?

@tima

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

@mpdehaan
@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.
9d5a79f
@tima

OK. Resubmitted. That should do it.

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

merging, thanks!

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