# ansible - index counter with "with\_item"

**URL:** <https://forum.ansible.com/t/ansible-index-counter-with-with-item/26177>\
**Category:** Ansible Project\
**Created:** [November 30, 2017, 4:09pm UTC](https://forum.ansible.com/t/ansible-index-counter-with-with-item/26177 "2017-11-30T16:09:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Moris\_Amar](https://avatars.discourse-cdn.com/v4/letter/m/258eb7/32.png) [@Moris\_Amar](https://forum.ansible.com/u/Moris_Amar)\
**Post date:** [November 30, 2017, 4:09pm UTC](https://forum.ansible.com/t/ansible-index-counter-with-with-item/26177/1 "2017-11-30T16:09:43Z")

</div>

Hi,

I want to have a counter (incrementation) in “with\_items” in order to look over a list (index).

ec2\_metric\_alarm:

…  
description: ‘{{ item.ec2\_alarm\_description }}’  
dimensions: ‘{{item.ec2\_alarm\_dimensions }}’

alarm\_actions: ‘{{ ec2\_scaling\_policy\_reg.results[**0**].arn }}’  
with\_items: ‘{{ ec2\_metric\_alarm\_item }}’

Any suggestion?

thanks

---

<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:** [November 30, 2017, 7:51pm UTC](https://forum.ansible.com/t/ansible-index-counter-with-with-item/26177/2 "2017-11-30T19:51:12Z")

</div>

Use with\_indexed\_items instead

[http://docs.ansible.com/ansible/latest/playbooks\_loops.html#looping-over-a-list-with-an-index](http://docs.ansible.com/ansible/latest/playbooks_loops.html#looping-over-a-list-with-an-index)
