0

I have an Ansible inventory file, with a group that contains roughly 20 children groups. I want to return the list of children so I started with:

{% for group in groups[maingroup] %}
    {{ group }}
{% endfor %}

Next, how can I add next to the group its length, comma separated?

I was thinking something like this would work but it doesn't:

{{ group|join(',', attribute='length') }}

Ideal output would be:

group_A,3
group_B,12
group_C,26 
techraf
  • 64,883
  • 27
  • 193
  • 198

1 Answers1

1

There is no reason to use join. You are using templating language, so use it in a simple way:

{% for group in groups[maingroup] %}
    {{ group }},{{ group|length }}
{% endfor %}
techraf
  • 64,883
  • 27
  • 193
  • 198