# Grouping subelements

**URL:** <https://forum.ansible.com/t/grouping-subelements/35921>\
**Category:** Ansible Project\
**Created:** [October 25, 2021, 6:37pm UTC](https://forum.ansible.com/t/grouping-subelements/35921 "2021-10-25T18:37:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anil\_Kommareddy](https://avatars.discourse-cdn.com/v4/letter/a/96bed5/32.png) [@Anil\_Kommareddy](https://forum.ansible.com/u/Anil_Kommareddy)\
**Post date:** [October 25, 2021, 6:37pm UTC](https://forum.ansible.com/t/grouping-subelements/35921/1 "2021-10-25T18:37:56Z")

</div>

Hi All,

How do I group sublement port under portnames?

- name: Test flatten - 1  
debug:  
msg: “{{ item[1].port | join(‘,’) }}”  
with\_subelements:
- “{{ new\_host\_groups }}”
- portnames

----------------json file —

{  
“name”: “sda”,  
“portnames”: [  
{  
“nickname”: “sdap1”,  
“port”: “2001000e1e4548956”,  
“type”: “fc”  
},  
{  
“nickname”: “sdap2”,  
“port”: “2001000e1e656562”,  
“type”: “fc”  
},  
{  
“nickname”: “sdap3”,  
“port”: “2001000e1ec23434”,  
“type”: “fc”  
},  
{  
“nickname”: “gladsto2p4”,  
“port”: “2001000e1ec25656”,  
“type”: “fc”  
}  
]  
}
