I just noticed, if you break the when into two clauses, instead of doing 
"not (...)" you can do this:

 - name: ods
   shell: "/something {{state}}"
   when:

    - ods

    - ansible_hostname is not search("demlh*")
   register: sss_ods_out
   notify: output ods
   ignore_errors: yes


On Sunday, May 27, 2018 at 12:00:17 PM UTC-5, Dan Linder wrote:
>
> The "when" stanza performs a AND when there are multiple when conditions (
> http://docs.ansible.com/ansible/latest/user_guide/playbooks_conditionals.html#the-when-statement
> ).
>
> Whenever I encounter a problem with 'when' I try to break it up to 
> multiple lines so the numerous parenthesis aren't causing confusion:
>
>  - name: ods
>    shell: "/something {{state}}"
>    when:
>
>     - ods
>
>     - not (ansible_hostname | search("demlh*"))
>    register: sss_ods_out
>    notify: output ods
>    ignore_errors: yes
>
> With that you might be able to deduce why the "AND" clause isn't working 
> as expected.
>
> It might also be that the "ansible_hostname | search(...)" might need to 
> change to "ansible_hostname is search(...)" (change | to is).
>
> If not, can you provide what "ods" contains?  A simple "debug:" before 
> that call should suffice.
>
> On Sunday, May 27, 2018 at 10:51:15 AM UTC-5, Pranay Nanda wrote:
>>
>> 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.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/9356ba57-3386-47f9-94ed-dda78aa446c4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to