# How to iterate over hash of arrays

**URL:** <https://forum.ansible.com/t/how-to-iterate-over-hash-of-arrays/23711>\
**Category:** Ansible Project\
**Created:** [February 11, 2017, 3:14pm UTC](https://forum.ansible.com/t/how-to-iterate-over-hash-of-arrays/23711 "2017-02-11T15:14:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![D11](https://avatars.discourse-cdn.com/v4/letter/d/47e85d/32.png) [@D11](https://forum.ansible.com/u/D11)\
**Post date:** [February 11, 2017, 3:14pm UTC](https://forum.ansible.com/t/how-to-iterate-over-hash-of-arrays/23711/1 "2017-02-11T15:14:50Z")

</div>

Hello,

I have below strucure.

vars:  
locations:

- parent\_location: A  
child\_location:
- a1
- a2
- a3
- parent\_location: B  
child\_location:
- b1
- b2
- b3
- parent\_location: C  
child\_location:
- c1
- c2
- c3

now i have task something like below

command:  
some-command ‘{{ A }}’ create

command:  
some-command ‘{{ a1 }}’ --parent ‘{{ A }}’

command:  
some-command ‘{{ b1 }}’ --parent ‘{{ B }}’

and so-on, what’s best way to achieve it ?

Thanks,  
DJ

---

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [February 13, 2017, 2:24pm UTC](https://forum.ansible.com/t/how-to-iterate-over-hash-of-arrays/23711/2 "2017-02-13T14:24:11Z")

</div>

Read the docs? 😉  
[http://docs.ansible.com/playbooks\_loops.html](http://docs.ansible.com/playbooks_loops.html)  
[https://docs.ansible.com/ansible/playbooks\_loops.html#looping-over-hashes](https://docs.ansible.com/ansible/playbooks_loops.html#looping-over-hashes)  
[https://docs.ansible.com/ansible/playbooks\_loops.html#nested-loops](https://docs.ansible.com/ansible/playbooks_loops.html#nested-loops)

Something along the lines of:

command: some-command "{{ item.parent\_location }}" create  
with\_dict: "{{ locations }}"

I guess for the child\_locations you might need to adapt with\_nested  
somehow.

Johannes
