On Tue, Jun 14, 2022 at 10:03 AM [email protected] <
[email protected]> wrote:

> Hello,
> I've  got a list variable  that looks like this
> list:
>    - name: n1
>      group: g1
>    - name: n2
>      group: g1
>    - name: c1
>      group: g2
> etc....
>
>
> in my config  file, this should become:
> g1: n1,n2
> g2: c1
>


I'm assuming a *config file* here, so can you render it? The example format
he docs on the groupby module comes in handy.
https://jinja.palletsprojects.com/en/3.1.x/templates/#jinja-filters.groupby

{% for group, values in (list | groupby('group') %}
{{ group }}:{% for item in value %}{{ item }},{% endfor %}
{% endfor %}

Hugo F. Gonzalez

Automation Architect, Solutions & Technology Practices LATAM

Red Hat Services  <https://www.redhat.com/>

[email protected]
M: +52-5531490291
<https://www.redhat.com/>

Need help from STP Latam? Open your request here
<https://docs.google.com/forms/d/e/1FAIpQLSfEVTfBWbvzBYv2Mx6Ye-LK5SRn0ZZ9ZCqfrYjHRJLK674WHQ/viewform?vc=0&c=0&w=1>



>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAH_36trn5mz1fdqr3QYCBqkbOsOXC5wbZe17kKx_oML67D4C2g%40mail.gmail.com.

Reply via email to