Is it possible to get the child groups of a given group in an expression

9 views
Skip to first unread message

Mark Davis

unread,
Jul 6, 2016, 5:16:31 PM7/6/16
to Ansible Project
From a quick look at https://github.com/ansible/ansible/blob/devel/lib/ansible/inventory/group.py I think the answer is "no" as child_groups doesn't have a getter, but just in case..

Is it possible to get the list of child groups of a given group?

The use case here would be for a jinja template (pseudo):

{% for my_group in groups['my-cluster'] %}
   
{
     
"name" : "{{ my_group.name }}",
     
"hosts" : [
     
{% for host in groups['{{ my_group.name }}] %}{"fqdn" : "{{ hostvars[host]['inventory_hostname'] }}"}{% if not loop.last %},{% endif %}
      {% endfor %}]
    }{% if not loop.last %},{% endif %}
{% endfor %}


There is an easy workaround which involves some duplication, but just curious if there's a way to get the above to work.




Reply all
Reply to author
Forward
0 new messages