# Problem with variables

**URL:** <https://forum.ansible.com/t/problem-with-variables/19011>\
**Category:** Ansible Project\
**Created:** [August 13, 2015, 7:42pm UTC](https://forum.ansible.com/t/problem-with-variables/19011 "2015-08-13T19:42:09Z")\
**Posts on this page:** 5\
**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:** [August 13, 2015, 7:42pm UTC](https://forum.ansible.com/t/problem-with-variables/19011/1 "2015-08-13T19:42:09Z")

</div>

Hi all,

The ansible docs, [here](http://docs.ansible.com/ansible/playbooks_variables.html#variables-defined-in-a-playbook), claim that you can assign a variable to a host inline in a playbook. Then, [here](http://docs.ansible.com/ansible/playbooks_conditionals.html#applying-when-to-roles-and-includes), it says you can use “when” paired with a variable to run certain roles on certain hosts. Why then, does this not work?

`

---

<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:** [August 13, 2015, 7:52pm UTC](https://forum.ansible.com/t/problem-with-variables/19011/2 "2015-08-13T19:52:41Z")

</div>

you are missing a colon:

- { role: syslog-client, when: type == "syslog" }

fyi, setting the var that way sets it always for all hosts, so that  
when statement is always true.

---

<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:** [August 13, 2015, 8:21pm UTC](https://forum.ansible.com/t/problem-with-variables/19011/3 "2015-08-13T20:21:20Z")

</div>

Hey Brian, thanks for the prompt reply.

Ok, so the colon got that running. So, what I actually mean to do with this playbook is the opposite, run the second play on all servers EXCEPT the one from the first play. What is the ansible equivalent of the boolean “not”? I’ve tried both when: type =! “syslog” and when: type not “syslog” and neither works. How would I implement this?

Thanks again!

---

<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:** [August 13, 2015, 8:22pm UTC](https://forum.ansible.com/t/problem-with-variables/19011/4 "2015-08-13T20:22:47Z")

</div>

!= , also note that 'type' will NOT be visible in the 2nd play as you  
defined it as a play level variable, you want to use set\_fact in this  
case.

---

<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:** [August 13, 2015, 8:29pm UTC](https://forum.ansible.com/t/problem-with-variables/19011/5 "2015-08-13T20:29:22Z")

</div>

Of course its !=. My brain is not working today. I need a vacation…  
Thanks for the tip on set\_fact, I’ll look into it a bit more.  
Thanks again for all the help!
