Get groupname(s) from inventory

32 views
Skip to first unread message

René Gallati

unread,
Feb 15, 2016, 8:14:23 AM2/15/16
to Ansible Project
Hello all,

is it possible to get the groupname(s) where a host is placed from inventory to use later? I have a situation like this:

[setA]
HostA
HostB

[setB]
HostC
HostD

[setC]
HostE
HostF

So when I'm running on HostC, it should somehow know it is in setB so that I can iterate over all other hosts in the same group and do something specific with that.
I know how to do it manually, but it looks very redundant in the config file to add a custom variable like

[setN]
HostXX set_name=setN
HostXY set_name=setN


just to be able to get at the group name.

Thanks for any hints

Dennis Benzinger | SAP Hybris

unread,
Feb 15, 2016, 12:10:52 PM2/15/16
to Ansible Project
Hello René,

you can use the group_names and groups variables: http://docs.ansible.com/ansible/playbooks_variables.html#magic-variables-and-how-to-access-information-about-other-hosts


Hope this helps,
Dennis Benzinger | SAP Hybris

René Gallati

unread,
Feb 19, 2016, 6:10:14 PM2/19/16
to Ansible Project
Thanks, that was exactly what I needed! I seem to have skipped over that part as I've read that page before. In any case, I can do now what I need. Thanks!
Reply all
Reply to author
Forward
0 new messages