# Three and more conditions in playbook

**URL:** <https://forum.ansible.com/t/three-and-more-conditions-in-playbook/15958>\
**Category:** Ansible Project\
**Created:** [August 15, 2014, 11:32am UTC](https://forum.ansible.com/t/three-and-more-conditions-in-playbook/15958 "2014-08-15T11:32:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sergei\_Antipov](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@Sergei\_Antipov](https://forum.ansible.com/u/Sergei_Antipov)\
**Post date:** [August 15, 2014, 11:32am UTC](https://forum.ansible.com/t/three-and-more-conditions-in-playbook/15958/1 "2014-08-15T11:32:17Z")

</div>

Hello.

This is possible to add more than 2 conditions like this?

- shell: ifdown {{ item.item.device }}; ifup {{ item.item.device }}  
with\_items: ether\_result.results  
when: ether\_result is defined and and item.changed and ether\_int\_status|failed

ether\_result and ether\_int\_status are registered variables.

---

<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:** [August 15, 2014, 1:18pm UTC](https://forum.ansible.com/t/three-and-more-conditions-in-playbook/15958/2 "2014-08-15T13:18:31Z")

</div>

Yes, this would also be easy for you to test and try on your own too 🙂

You can also do:

- shell: foo  
when:
- a == b
- c == d
- e == f

And do ands that way, can sometimes be easier to read.

---

<div class="post-metadata">

**Author:** ![Sergei\_Antipov](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@Sergei\_Antipov](https://forum.ansible.com/u/Sergei_Antipov)\
**Post date:** [August 18, 2014, 5:07am UTC](https://forum.ansible.com/t/three-and-more-conditions-in-playbook/15958/3 "2014-08-18T05:07:13Z")

</div>

when:

- ether\_result is defined
- item|changed
- ether\_int\_status|failed

This variant not work for me.  
This works:

when:

- ether\_result is defined
- ether\_int\_status|failed

More than 2 conditions not work…((

---

<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:** [August 18, 2014, 12:31pm UTC](https://forum.ansible.com/t/three-and-more-conditions-in-playbook/15958/4 "2014-08-18T12:31:22Z")

</div>

“More than 2 conditions not work…((”

There’s nothing in the code that has any bearing on how many conditions there are that makes 2 special, it’s either “single” or “more than one”

That being said, if you can explain what “doesn’t work” looks like and provide a minimal playbook with output, we can try to reproduce what you are seeing.

Thanks!

---

<div class="post-metadata">

**Author:** ![Sergei\_Antipov](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@Sergei\_Antipov](https://forum.ansible.com/u/Sergei_Antipov)\
**Post date:** [August 19, 2014, 3:08am UTC](https://forum.ansible.com/t/three-and-more-conditions-in-playbook/15958/5 "2014-08-19T03:08:22Z")

</div>

Thank you.

I found 2 errors in my code: 1 logical and 1 syntax.  
Right conditions:
