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!
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.
-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.
try this:
when: alias not in ['leia', 'luke', 'vader'}
^ so when alias is neither of those, which i think is what you wanted.
@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!