# Issue with conditionals

**URL:** <https://forum.ansible.com/t/issue-with-conditionals/20120>\
**Category:** Ansible Project\
**Created:** [January 4, 2016, 5:59pm UTC](https://forum.ansible.com/t/issue-with-conditionals/20120 "2016-01-04T17:59:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eugene\_Romero](https://avatars.discourse-cdn.com/v4/letter/e/919ad9/32.png) [@Eugene\_Romero](https://forum.ansible.com/u/Eugene_Romero)\
**Post date:** [January 4, 2016, 5:59pm UTC](https://forum.ansible.com/t/issue-with-conditionals/20120/1 "2016-01-04T17:59:00Z")

</div>

Hi guys! I’m experiencing an interesting issue that I can’t figure out.

Every host in my inventory file has an “alias” variable assigned to it.

Now, I’m trying to run a template play on some of the hosts:

- name: Hosts file  
template:  
src=hosts.j2  
dest=/etc/hosts  
when: (alias != “leia”) or (alias != “luke”) or (alias != “vader”)

If I turn those conditionals from != to ==, the play only runs on those 3 servers as expected. But if I run it like it is above, it runs on ALL hosts.

What am I dong wrong?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Josh\_Smift1](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@Josh\_Smift1](https://forum.ansible.com/u/Josh_Smift1)\
**Post date:** [January 4, 2016, 6:07pm UTC](https://forum.ansible.com/t/issue-with-conditionals/20120/2 "2016-01-04T18:07:01Z")

</div>

> &nbsp;&nbsp;when: (alias != "leia") or (alias != "luke") or (alias != "vader")
> 
> If I turn those conditionals from != to ==, the play only runs on  
> those 3 servers as expected. But if I run it like it is above, it runs  
> on ALL hosts.

No matter what your alias is, at least one of those conditions will be  
true (in practice, two or three of them will be), and the OR means that if  
one of them is true, the whole 'when' is true.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-Josh (jbs@care.com)

This email is intended for the person(s) to whom it is addressed and may contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, distribution, copying, or disclosure by any person other than the addressee(s) is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and delete the message and any attachments from your system.

---

<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 4, 2016, 6:16pm UTC](https://forum.ansible.com/t/issue-with-conditionals/20120/3 "2016-01-04T18:16:57Z")

</div>

try this:

when: alias not in ['leia', 'luke', 'vader'}

^ so when alias is neither of those, which i think is what you wanted.

---

<div class="post-metadata">

**Author:** ![Eugene\_Romero](https://avatars.discourse-cdn.com/v4/letter/e/919ad9/32.png) [@Eugene\_Romero](https://forum.ansible.com/u/Eugene_Romero)\
**Post date:** [January 4, 2016, 7:17pm UTC](https://forum.ansible.com/t/issue-with-conditionals/20120/4 "2016-01-04T19:17:04Z")

</div>

@Josh Smift:

Ahh, that explanation makes total sense. I see now why this didn’t work. Thanks for that!

@ Brian Coca:

That worked beautifully. Thanks a lot!
