Is there any way to access the list of hosts within each
"groups" (magic) variable ?
{% if 'webserver' in groups %}
# some part of a configuration file that only applies to webservers
{% endif %}
Kumar
Is there any way to access the list of hosts within each
"groups" (magic) variable ?
{% if 'webserver' in groups %}
# some part of a configuration file that only applies to webservers
{% endif %}
Kumar
Yep.
groups is already a (Python) list in this example, this example is a test to see if an item is in a list.
Thanks Michael:
I think I was not clear in my prior email. In the example below, I
am trying to print all the host name associated to the group
'webserver'.
I am assuming there might be a method on each group element in the
list or some other way to access the list of hosts name associated to
a group in the
inventory file. I would like the script to dynamically pull all the
hosts associated to a group.
Thanks,
Inventory file:
[webservers]
foo.example.com
bar.example.com
xyz.example.com
{% if 'webserver' in groups %}
# print all the host names associated with the webservers groups
# i.e foo.example.com, bar.example.com, xyz.example.com
{% endif %}
I am assuming there might be a method on each group element in the
list or some other way to access the list of hosts name associated to
a group in the
inventory file. I would like the script to dynamically pull all the
hosts associated to a group.
Sounds like you are trying to read this from another application.
The most obvious answer here is you could use the ansible inventory API.