# How to loop over multiple subkeys?

**URL:** <https://forum.ansible.com/t/how-to-loop-over-multiple-subkeys/22312>\
**Category:** Ansible Project\
**Created:** [August 18, 2016, 3:13am UTC](https://forum.ansible.com/t/how-to-loop-over-multiple-subkeys/22312 "2016-08-18T03:13:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ash](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Ash](https://forum.ansible.com/u/Ash)\
**Post date:** [August 18, 2016, 3:13am UTC](https://forum.ansible.com/t/how-to-loop-over-multiple-subkeys/22312/1 "2016-08-18T03:13:21Z")

</div>

Consider the following:

`  
users:

- name: a  
phone\_parents:
- 123123123
- 234234234  
phone\_roommate:
- 456456456
- 567567567
- name: b  
phone\_parents:
- 789789789  
phone\_roommate:
- 890890890
- 678678678

`

With subelement, I can only define one subkey per loop:

`

- debug: msg=“Contacts: {{ item.1 }}”  
with\_subelements:
- “{{ users }}”
- phone\_parents

`

My result is as expected:

`

“msg”: “Contacts: 123123123”  
“msg”: “Contacts: 234234234”  
“msg”: “Contacts: 789789798”

`

However, I would like to have all phone numbers (phone\_parents + phone\_roommate) in a single loop like the following:

`

“msg”: “Contacts: 123123123”  
“msg”: “Contacts: 234234234”  
“msg”: “Contacts: 456456456”

“msg”: “Contacts: 567567567”  
“msg”: “Contacts: 789789789”  
“msg”: “Contacts: 890809890”

“msg”: “Contacts: 678678678”

`

How can I achieve that with Ansible?
