# Combine with\_items with when.

**URL:** <https://forum.ansible.com/t/combine-with-items-with-when/18180>\
**Category:** Ansible Project\
**Created:** [May 7, 2015, 6:13am UTC](https://forum.ansible.com/t/combine-with-items-with-when/18180 "2015-05-07T06:13:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonas\_Rottmann](https://avatars.discourse-cdn.com/v4/letter/j/e47c2d/32.png) [@Jonas\_Rottmann](https://forum.ansible.com/u/Jonas_Rottmann)\
**Post date:** [May 7, 2015, 6:13am UTC](https://forum.ansible.com/t/combine-with-items-with-when/18180/1 "2015-05-07T06:13:49Z")

</div>

Hi,

Is it possible to combine with\_items with when? so i.e.

- name: Vhosts apache config  
template: src=apache\_vhost.j2 dest=/etc/apache2/sites-available/{{ item.domain }}.conf  
with\_items: apache.vhosts  
when: “ansible\_os\_family == ‘Debian’ and item.state == ‘availible’”  
tags:
- apache  
notify:
- reload apache2

For this I get: error while evaluating conditional

so I can choose for the loop if it is run according to an property set on this item?

If not is there a workaround or anything for it?

Thanks

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [May 7, 2015, 2:21pm UTC](https://forum.ansible.com/t/combine-with-items-with-when/18180/2 "2015-05-07T14:21:56Z")

</div>

yes, when runs after with\_ and can use the item variable, your problem  
is with quoting, not the items.

&nbsp;&nbsp;when: ansible\_os\_family == 'Debian' and item.state == 'available'

The when is always templated (implicit {{ }} around it), if you quote  
the whole thing it will get looked at as a string.

---

<div class="post-metadata">

**Author:** ![Jonas\_Rottmann](https://avatars.discourse-cdn.com/v4/letter/j/e47c2d/32.png) [@Jonas\_Rottmann](https://forum.ansible.com/u/Jonas_Rottmann)\
**Post date:** [May 8, 2015, 10:42am UTC](https://forum.ansible.com/t/combine-with-items-with-when/18180/3 "2015-05-08T10:42:26Z")

</div>

Hi,

Without quotes I get the same error without quotes…

- name: Vhosts apache config  
template: src=apache\_vhost.j2 dest=/etc/apache2/sites-available/{{ item.domain }}.conf  
with\_items: apache.vhosts  
when: ansible\_os\_family == ‘Debian’ and item.state == ‘availible’  
tags:
- apache  
notify:
- reload apache2

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [May 8, 2015, 4:29pm UTC](https://forum.ansible.com/t/combine-with-items-with-when/18180/4 "2015-05-08T16:29:34Z")

</div>

does every list entry in apache.vhosts have 'state'?
