# Is there any way to create a nested loop over a dict and a list?

**URL:** <https://forum.ansible.com/t/is-there-any-way-to-create-a-nested-loop-over-a-dict-and-a-list/19281>\
**Category:** Ansible Project\
**Created:** [September 17, 2015, 2:04am UTC](https://forum.ansible.com/t/is-there-any-way-to-create-a-nested-loop-over-a-dict-and-a-list/19281 "2015-09-17T02:04:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![user73](https://avatars.discourse-cdn.com/v4/letter/u/4bbf92/32.png) [@user73](https://forum.ansible.com/u/user73)\
**Post date:** [September 17, 2015, 2:04am UTC](https://forum.ansible.com/t/is-there-any-way-to-create-a-nested-loop-over-a-dict-and-a-list/19281/1 "2015-09-17T02:04:52Z")

</div>

Say I have two variable like these:

```auto
var1:
  key1: val1
  key2: val2
var2:
  - item1
  - item2

```

Can I loop over these two variables like below?

```auto
- shell: echo {{ item.0.value }} {{ item.1 }}
  with_dict: "{{ var1 }}"
  with_items: "{{ var2 }}"

```

I have no idea to loop over these two variables together and don’t wanna change the data type of the variables. Is there any way to achieve this kind of loop in ansible?

---

<div class="post-metadata">

**Author:** ![Takeshi\_Yaegashi](https://avatars.discourse-cdn.com/v4/letter/t/838e76/32.png) [@Takeshi\_Yaegashi](https://forum.ansible.com/u/Takeshi_Yaegashi)\
**Post date:** [September 18, 2015, 6:19am UTC](https://forum.ansible.com/t/is-there-any-way-to-create-a-nested-loop-over-a-dict-and-a-list/19281/2 "2015-09-18T06:19:10Z")

</div>

Hello,

You can use with\_nested:

`

- shell: “echo {{item.0}} {{item.1}}”  
with\_nested:
- var1.values()
- var2

`
