# with\_dict in loop counter

**URL:** <https://forum.ansible.com/t/with-dict-in-loop-counter/31846>\
**Category:** Ansible Project\
**Tags:** azure\
**Created:** [December 18, 2019, 2:09pm UTC](https://forum.ansible.com/t/with-dict-in-loop-counter/31846 "2019-12-18T14:09:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafael\_Tomelin](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@Rafael\_Tomelin](https://forum.ansible.com/u/Rafael_Tomelin)\
**Post date:** [December 18, 2019, 2:09pm UTC](https://forum.ansible.com/t/with-dict-in-loop-counter/31846/1 "2019-12-18T14:09:02Z")

</div>

Hi,

I have a task for creating the virtual machine at Azure with\_dict.

I should like to create a variable count (number the VMS) and put it with\_dict.

How can create loop count with with\_dict?

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [December 18, 2019, 2:53pm UTC](https://forum.ansible.com/t/with-dict-in-loop-counter/31846/2 "2019-12-18T14:53:33Z")

</div>

This can be done using loop\_control.extended: [https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_loops.html#extended-loop-variables](https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html#extended-loop-variables)

Examples:

- debug:  
msg: “{{ ansible\_loop.index0 }}: key: {{ item.key }}, value: {{ item.value }}”  
with\_dict: “{{ thing }}”  
loop\_control:  
extended: true

- debug:  
msg: “{{ ansible\_loop.index0 }}: key: {{ item.key }}, value: {{ item.value }}”  
loop: “{{ thing|dict2items }}”  
loop\_control:  
extended: true
