# Use included circles and expressions in 'with\_items' and 'when' statement

**URL:** <https://forum.ansible.com/t/use-included-circles-and-expressions-in-with-items-and-when-statement/16769>\
**Category:** Ansible Project\
**Created:** [November 13, 2014, 8:56am UTC](https://forum.ansible.com/t/use-included-circles-and-expressions-in-with-items-and-when-statement/16769 "2014-11-13T08:56:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![user18](https://avatars.discourse-cdn.com/v4/letter/u/6a8cbe/32.png) [@user18](https://forum.ansible.com/u/user18)\
**Post date:** [November 13, 2014, 8:56am UTC](https://forum.ansible.com/t/use-included-circles-and-expressions-in-with-items-and-when-statement/16769/1 "2014-11-13T08:56:34Z")

</div>

Hi!

I have a problem with with\_items+when statement, please help me. In Jinja2 syntax it’s like this:

`

- debug: msg=“{% for item in vfiles%}{% for bin in item.binaries %}{% if  
bin.name+‘.’+bin.ext in files.stdout\_lines %}{{item.container}}{% endif  
%}{% endfor %}{% endfor %}”

`

P.S. Sorry for my english.

---

<div class="post-metadata">

**Author:** ![user18](https://avatars.discourse-cdn.com/v4/letter/u/6a8cbe/32.png) [@user18](https://forum.ansible.com/u/user18)\
**Post date:** [November 13, 2014, 10:28am UTC](https://forum.ansible.com/t/use-included-circles-and-expressions-in-with-items-and-when-statement/16769/2 "2014-11-13T10:28:09Z")

</div>

Now i use

`

- set\_fact: tmpvar=“{% for item in vfiles%}{% for bin in item.binaries %}{% if bin.name+‘.’+bin.ext in files.stdout\_lines %}{{item.container}} {% endif %}{% endfor %}{% endfor %}”

- debug: var=item  
with\_items:

- “{{tmpvar.split()}}”

`

Maybe there is an better way?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [November 17, 2014, 9:16pm UTC](https://forum.ansible.com/t/use-included-circles-and-expressions-in-with-items-and-when-statement/16769/3 "2014-11-17T21:16:00Z")

</div>

Generally ansible frowns upon usages that are too “code-like” and tries to find some other ways to solve them that are easier to read.

Can we talk about your underlying use case that you are trying to model, to suggest an alternative, easier approach?
