# Multiple conditions not working

**URL:** <https://forum.ansible.com/t/multiple-conditions-not-working/27643>\
**Category:** Ansible Developer\
**Created:** [May 27, 2018, 4:07pm UTC](https://forum.ansible.com/t/multiple-conditions-not-working/27643 "2018-05-27T16:07:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pranay\_Nanda](https://avatars.discourse-cdn.com/v4/letter/p/a9a28c/32.png) [@Pranay\_Nanda](https://forum.ansible.com/u/Pranay_Nanda)\
**Post date:** [May 27, 2018, 4:07pm UTC](https://forum.ansible.com/t/multiple-conditions-not-working/27643/1 "2018-05-27T16:07:21Z")

</div>

I want to run few tasks in shell if they satisfy a condition. Strangely the task runs if the second condition is satisfied even though the first one fails.

name: ods  
shell: “/something {{state}}”  
when: ((ods) and (not (ansible\_hostname | search(“demlh\*”))))  
register: sss\_ods\_out  
notify: output ods  
ignore\_errors: yes

Here sss\_ods is a variable defined in a vars file. If I remove the latter condition the task would run but I want both the conditions to be satisfied for the task to run and I can’t understand where am I going wrong.

---

<div class="post-metadata">

**Author:** ![ipitythaphool](https://avatars.discourse-cdn.com/v4/letter/i/6de8d8/32.png) [@ipitythaphool](https://forum.ansible.com/u/ipitythaphool)\
**Post date:** [May 28, 2018, 8:01pm UTC](https://forum.ansible.com/t/multiple-conditions-not-working/27643/2 "2018-05-28T20:01:10Z")

</div>

Firstly I'd try simplifying (and making it more readable) your when by making it a list. You also need to add a . to your pattern by the looks

When:  
&nbsp;&nbsp;- condition1  
&nbsp;&nbsp;- blah | search("pattern.\*")
