# When condition to check domainName

**URL:** <https://forum.ansible.com/t/when-condition-to-check-domainname/30164>\
**Category:** Ansible Project\
**Created:** [April 22, 2019, 11:28pm UTC](https://forum.ansible.com/t/when-condition-to-check-domainname/30164 "2019-04-22T23:28:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raj5](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@Raj5](https://forum.ansible.com/u/Raj5)\
**Post date:** [April 22, 2019, 11:28pm UTC](https://forum.ansible.com/t/when-condition-to-check-domainname/30164/1 "2019-04-22T23:28:02Z")

</div>

Hello,

I am running into an issue, this is simple playbook which tries to copy right config file based on Domain name, I tried executing below code snippet it’s skipping the non prod and executing prod, Not sure whats wrong here, can some one throw a light here.

`

- name: Gathering facts locally at role level  
setup:  
filter: ansible\_\*

- set\_fact:  
domainName: “{{ ansible\_fqdn.split(‘.’, 1)[1] }}”

- name: Display all variables/facts known for a host  
debug:  
var: domainName

- name: Copy the non prod config file  
win\_template:  
src: nonprod.yaml.j2  
dest: C:\ProgramData\program\file.yaml  
newline\_sequence: \n  
when: ((domainName == “AD1”) or (domainName == “AD2”))

- name: Copy the prod config file  
win\_template:  
src: prod.yaml.j2  
dest: C:\ProgramData\program\file.yaml  
when: ((domainName != “AD1”) or (domainName != “AD2”))  
`

Thanks and Regards  
Raj

---

<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:** [April 23, 2019, 2:20am UTC](https://forum.ansible.com/t/when-condition-to-check-domainname/30164/2 "2019-04-23T02:20:36Z")

</div>

Mustaches don't stack,

when: ((domainName == "AD1") or (domainName == "AD2")) \<= no  
mustaches needed when 'when:', you are trying to do double  
interpolation (conditionals have implicit {{ }})

Also you probably want to use 'in' instead of multiple comparisons:

&nbsp;&nbsp;when: domainName in ["AD1", "AD2"]

---

<div class="post-metadata">

**Author:** ![Raj5](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@Raj5](https://forum.ansible.com/u/Raj5)\
**Post date:** [April 26, 2019, 5:08pm UTC](https://forum.ansible.com/t/when-condition-to-check-domainname/30164/3 "2019-04-26T17:08:05Z")

</div>

Thanks for the explanation Brian, you are “Awesome”. I’ve used “When & In” and it worked.
