# multiple when condition not working in playbook

**URL:** <https://forum.ansible.com/t/multiple-when-condition-not-working-in-playbook/20240>\
**Category:** Ansible Project\
**Created:** [January 16, 2016, 8:25pm UTC](https://forum.ansible.com/t/multiple-when-condition-not-working-in-playbook/20240 "2016-01-16T20:25:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DHAVAL\_JAISWAL](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@DHAVAL\_JAISWAL](https://forum.ansible.com/u/DHAVAL_JAISWAL)\
**Post date:** [January 16, 2016, 8:25pm UTC](https://forum.ansible.com/t/multiple-when-condition-not-working-in-playbook/20240/1 "2016-01-16T20:25:59Z")

</div>

Hi,

Trying to write playbook with when conditional statement.

However, it always choose last command (/home/user//bin/) to execute even though condition matches with another domainname.

playbook.yml

# command execution Ansible Playbooks

- hosts: “{{domainname}}”  
remote\_user:   
vars\_prompt:
- name: “domainname”  
prompt: “Enter domain name”  
private: no  
tasks:
- name: Copy file to client  
copy: src=/tmp/{{file\_name}} dest=/tmp/ owner= group=user mode=0644  
become: yes  
become\_method: su

tasks:

- name: installing something  
command: /home/user//bin/  
become: yes  
become\_method: su  
when: (‘“{{domainname}}” == “[test.com](http://test.com)”’) or (‘“{{domainname}}” == “[test1.com](http://test1.com)”’)
- command: /home/user//bin/  
become: yes  
become\_method: su  
when: (‘“{{domainname}}” == “[test5.com](http://test5.com)”’) or (‘“{{domainname}}” == “[test5.com](http://test5.com)”’)

While running above if i will enter **[test.com](http://test.com)** as a domain name still it will execute command (/home/user//bin/) instead of (/home/user//bin/)

Please correct me where i am making mistake.

---

<div class="post-metadata">

**Author:** ![DHAVAL\_JAISWAL](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@DHAVAL\_JAISWAL](https://forum.ansible.com/u/DHAVAL_JAISWAL)\
**Post date:** [January 18, 2016, 10:42am UTC](https://forum.ansible.com/t/multiple-when-condition-not-working-in-playbook/20240/2 "2016-01-18T10:42:43Z")

</div>

solved.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 18, 2016, 1:25pm UTC](https://forum.ansible.com/t/multiple-when-condition-not-working-in-playbook/20240/3 "2016-01-18T13:25:08Z")

</div>

don't use moustaches in the when:

when: (domainname == "test.com"') or (domainname == "test1.com)

though i suggest using:

when: domainname in ["test.com", "tes1.com"]
