# question about 'when' conditional

**URL:** <https://forum.ansible.com/t/question-about-when-conditional/25590>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [September 25, 2017, 1:59pm UTC](https://forum.ansible.com/t/question-about-when-conditional/25590 "2017-09-25T13:59:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christian\_Iuga](https://avatars.discourse-cdn.com/v4/letter/c/34f0e0/32.png) [@Christian\_Iuga](https://forum.ansible.com/u/Christian_Iuga)\
**Post date:** [September 25, 2017, 1:59pm UTC](https://forum.ansible.com/t/question-about-when-conditional/25590/1 "2017-09-25T13:59:50Z")

</div>

Hi,

It’s look like i don’t understand perfectly when condition:

1. 

tasks:

- set\_fact:  
sensu\_remote\_plugins:

- process-checks

- http

- disk-checks

- memory-checks

- load-checks

- cpu-checks

- io-checks

- rabbitmq

- network-checks

- name: debug  
debug:  
var=sensu\_remote\_plugins  
when: “‘aws’ in sensu\_remote\_plugins”

It’s work as expected, (skiping on this exemple) :

TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
skipping: [xxxx]

But i want a more complex when condition to filter with ansible\_os\_family

After sevral search, this when condition work’s for me :

when:

- ansible\_os\_family == “RedHat”
- “‘aws’ in sensu\_remote\_plugins”  
TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
skipping: [xxxx]

**But why these are not working ? :**

when: **(** ansible\_os\_family == “RedHat” **and** “‘aws’ in sensu\_remote\_plugins”**)**  
TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [xxxx] =\> {

when: **(**“‘aws’ in sensu\_remote\_plugins”**) and** ansible\_os\_family == “RedHat”

TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [xxxx] =\> {

when: **(**“‘aws’ in sensu\_remote\_plugins”**) and (ansible\_os\_family == “RedHat”)**  
TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [xxxx] =\> {

Thanks in advance

ansible 2.3.2.0

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [September 25, 2017, 2:36pm UTC](https://forum.ansible.com/t/question-about-when-conditional/25590/2 "2017-09-25T14:36:21Z")

</div>

too many quotes, in the first one they are needed for YAML  
restrictions, if you start a value with a quote, it must finish with a  
quote. These quotes are removed when passing to the evaluator, but not  
in other cases.

This should work:  
&nbsp;&nbsp;when: ansible\_os\_family == "RedHat" and 'aws' in sensu\_remote\_plugins

Also, lists are 'implicit AND'  
&nbsp;&nbsp;when:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- ansible\_os\_family == "RedHat"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- "'aws' in sensu\_remote\_plugins"
