# When var1 == "yes" and var2 == "no"

**URL:** <https://forum.ansible.com/t/when-var1-yes-and-var2-no/32205>\
**Category:** Ansible Project\
**Tags:** azure\
**Created:** [February 11, 2020, 5:44pm UTC](https://forum.ansible.com/t/when-var1-yes-and-var2-no/32205 "2020-02-11T17:44:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kzersatz](https://avatars.discourse-cdn.com/v4/letter/k/7bcc69/32.png) [@kzersatz](https://forum.ansible.com/u/kzersatz)\
**Post date:** [February 11, 2020, 5:44pm UTC](https://forum.ansible.com/t/when-var1-yes-and-var2-no/32205/1 "2020-02-11T17:44:53Z")

</div>

So,

I’m having fits with when conditionals matching strings  
No matter what I do, it applies each conditional, the combination of the variables doesn’t seem to count for … anything.

what the heck am I doing wrong? additionally, is there a better way to do this?

`

- name: H - Set FIM Flag - RW  
win\_domain\_group:  
when: share\_fim\_managed == “yes” and share\_azure\_managed == “no”  
domain\_server: “{{ h\_domain\_server }}”  
domain\_username: “{{ h\_domain\_username }}”  
domain\_password: “{{ h\_domain\_password }}”  
scope: global  
name: “{{ h\_g\_prefix }}{{ g\_name }}{{suffix\_RW}}”  
attributes:  
NCHIDMMGI: FIM Managed - ‘{{ dateformat }}’

- name: H - Set Azure Flag - RW  
win\_domain\_group:  
domain\_server: “{{ h\_domain\_server }}”  
domain\_username: “{{ h\_domain\_username }}”  
domain\_password: “{{ h\_domain\_password }}”  
scope: global  
name: “{{ h\_g\_prefix }}{{ g\_name }}{{suffix\_RW}}”  
attributes:  
NCHIDMMGI: Azure Managed - ‘{{ dateformat }}’  
when: share\_fim\_managed == “no” and share\_azure\_managed == “yes”

- name: R - Set FIM/Azure Flag - RW  
win\_domain\_group:  
domain\_server: “{{ r\_domain\_server }}”  
domain\_username: “{{ r\_domain\_username }}”  
domain\_password: “{{ r\_domain\_password }}”  
scope: global  
protect: yes  
name: “{{ r\_g\_prefix }}{{ g\_name }}{{suffix\_RW}}”  
attributes:  
NCHIDMMGI: FIM / Azure Managed - ‘{{ dateformat }}’  
when: share\_fim\_managed == “yes” and share\_azure\_managed == “yes”

## from the include file

share\_fim\_managed: “no”  
share\_azure\_managed: “yes”  
`

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [February 11, 2020, 5:49pm UTC](https://forum.ansible.com/t/when-var1-yes-and-var2-no/32205/2 "2020-02-11T17:49:29Z")

</div>

> So,
> 
> I'm having fits with when conditionals matching strings  
> No matter what I do, it applies each conditional, the combination of the variables doesn't seem to count for ... anything.
> 
> what the heck am I doing wrong? additionally, is there a better way to do this?

Hello Jessie,

it looks like your indentation is wrong. when is a task parameter and not a module parameter:

- name: ...  
&nbsp;&nbsp;win\_domain\_group:  
&nbsp;&nbsp;&nbsp;&nbsp;domain\_server:"{{ h\_domain\_server }}"  
&nbsp;&nbsp;&nbsp;&nbsp;...  
&nbsp;&nbsp;when: share\_fim\_managed =="yes"andshare\_azure\_managed =="no"

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![kzersatz](https://avatars.discourse-cdn.com/v4/letter/k/7bcc69/32.png) [@kzersatz](https://forum.ansible.com/u/kzersatz)\
**Post date:** [February 11, 2020, 6:05pm UTC](https://forum.ansible.com/t/when-var1-yes-and-var2-no/32205/3 "2020-02-11T18:05:27Z")

</div>

Perfect!

I didn’t realize the indentation had to be outside the module parameter, the example I was using was poorly written it seems.

I appreciate the help Stefan!

---

<div class="post-metadata">

**Author:** ![hugonz](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/hugonz/32/503_2.png) [@hugonz](https://forum.ansible.com/u/hugonz)\
**Post date:** [February 11, 2020, 9:34pm UTC](https://forum.ansible.com/t/when-var1-yes-and-var2-no/32205/4 "2020-02-11T21:34:05Z")

</div>

Are you actually comparing the strings "yes" and "no" to the variables? If they're actual booleans, you will be better off by doing:

when: share\_fim\_managed and not share\_azure\_managed

when: not share\_fim\_managed and share\_azure\_managed

when: share\_fim\_managed and share\_azure\_managed

All nonempty strings are true, even if they contain the strings "false" or "true", you should be careful when comparing truth values. See here:
