with_dict in loop counter

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?

This can be done using loop_control.extended: 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