# What is the preferred way to loop over items with varying when statements?

**URL:** <https://forum.ansible.com/t/what-is-the-preferred-way-to-loop-over-items-with-varying-when-statements/24453>\
**Category:** Ansible Project\
**Created:** [May 10, 2017, 8:03pm UTC](https://forum.ansible.com/t/what-is-the-preferred-way-to-loop-over-items-with-varying-when-statements/24453 "2017-05-10T20:03:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ed1](https://avatars.discourse-cdn.com/v4/letter/e/958977/32.png) [@Ed1](https://forum.ansible.com/u/Ed1)\
**Post date:** [May 10, 2017, 8:03pm UTC](https://forum.ansible.com/t/what-is-the-preferred-way-to-loop-over-items-with-varying-when-statements/24453/1 "2017-05-10T20:03:04Z")

</div>

I’ve got cases where I want to run the same task multiple times, with minor variances. I’ve been implementing that with a loop where each item has a property for its when statement, and the task itself resolves that property. With 2.3, I now receive warnings about the jinja expression. I can’t refer directly to the item’s when statement, since that’s handled as a string (and will resolve to true). What’s the best way to accomplish this, warning-free, in 2.3? Is there a filter I can use to do the evaluation?

Thanks,  
Ed

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [May 10, 2017, 8:51pm UTC](https://forum.ansible.com/t/what-is-the-preferred-way-to-loop-over-items-with-varying-when-statements/24453/2 "2017-05-10T20:51:42Z")

</div>

In when: the curly brackets is implied, so just remove them at the message says.

&nbsp;&nbsp;&nbsp;when: item.condition

---

<div class="post-metadata">

**Author:** ![Ed1](https://avatars.discourse-cdn.com/v4/letter/e/958977/32.png) [@Ed1](https://forum.ansible.com/u/Ed1)\
**Post date:** [May 10, 2017, 10:31pm UTC](https://forum.ansible.com/t/what-is-the-preferred-way-to-loop-over-items-with-varying-when-statements/24453/3 "2017-05-10T22:31:08Z")

</div>

The problem with just “item.condition” is item.condition is handled as a string (not an expression). As a result, both “7 \< 4” and “7 \> 4” evaluate to true.
