# When condition 'or' structure question

**URL:** <https://forum.ansible.com/t/when-condition-or-structure-question/31251>\
**Category:** Ansible Project\
**Created:** [September 10, 2019, 5:45pm UTC](https://forum.ansible.com/t/when-condition-or-structure-question/31251 "2019-09-10T17:45:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guy\_Knights1](https://avatars.discourse-cdn.com/v4/letter/g/82dd89/32.png) [@Guy\_Knights1](https://forum.ansible.com/u/Guy_Knights1)\
**Post date:** [September 10, 2019, 5:45pm UTC](https://forum.ansible.com/t/when-condition-or-structure-question/31251/1 "2019-09-10T17:45:45Z")

</div>

It’s possible to define a series of ‘and’ conditions for a task as follows:

when:

- foo == true
- bar == true

As far as I’m aware, the only way to define ‘or’ conditions is in-line, as such:

when: foo == true or bar == true

Is there any other way to define ‘or’ conditions, in a way that’s similar to the first example?

Thanks,  
Guy

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [September 10, 2019, 6:14pm UTC](https://forum.ansible.com/t/when-condition-or-structure-question/31251/2 "2019-09-10T18:14:21Z")

</div>

No. It is not. It can be simplified

&nbsp;&nbsp;&nbsp;when:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- foo  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- bar

&nbsp;&nbsp;&nbsp;when: foo or bar

Cheers,

&nbsp;&nbsp;-vlado

---

<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:** [September 10, 2019, 7:16pm UTC](https://forum.ansible.com/t/when-condition-or-structure-question/31251/3 "2019-09-10T19:16:04Z")

</div>

You can also do

&nbsp;&nbsp;when: true in [foo, bar]

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [September 10, 2019, 8:54pm UTC](https://forum.ansible.com/t/when-condition-or-structure-question/31251/4 "2019-09-10T20:54:15Z")

</div>

And

&nbsp;&nbsp;&nbsp;&nbsp;when: [foo, bar] is all

&nbsp;&nbsp;&nbsp;&nbsp;when: [foo, bar] is any

Cheers 🙂

&nbsp;&nbsp;-vlado
