# Conditional expression if alice in \['alice', 'bob'\]

**URL:** <https://forum.ansible.com/t/conditional-expression-if-alice-in-alice-bob/13813>\
**Category:** Ansible Project\
**Created:** [October 31, 2013, 2:00pm UTC](https://forum.ansible.com/t/conditional-expression-if-alice-in-alice-bob/13813 "2013-10-31T14:00:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Deon\_Bredenhann](https://avatars.discourse-cdn.com/v4/letter/d/c6cbf5/32.png) [@Deon\_Bredenhann](https://forum.ansible.com/u/Deon_Bredenhann)\
**Post date:** [October 31, 2013, 2:00pm UTC](https://forum.ansible.com/t/conditional-expression-if-alice-in-alice-bob/13813/1 "2013-10-31T14:00:07Z")

</div>

Hi all

So close.

I’m trying to set up users by passing a list of users and a hash of user configs.

#group\_vars/all  
user\_definitions:

- username: alice  
uid: 1101
- username: bob  
uid: 1102

#group\_vars/web  
install\_users:

- alice
- bob

#main.yml

- name: Install users  
user: name={{item.username}}  
when: ${item.username} in $install\_users  
with\_items: user\_definitions

fatal: [[vbox1.example.com](http://vbox1.example.com)] =\> Conditional expression must evaluate to True or False: {% if alice in [‘alice’, ‘bob’] %} True {% else %} False {% endif %}

I do not understand what the problem is. From the looks of the error, it looks like the first alice is a variable and the alice and bob are strings.

Any idea what I’m doing wrong?  
It feels like it should be something small.

Thanks  
Deon

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 31, 2013, 2:04pm UTC](https://forum.ansible.com/t/conditional-expression-if-alice-in-alice-bob/13813/2 "2013-10-31T14:04:12Z")

</div>

You should never use legacy variables anymore except in one very rare occasion (needing deep references to things in defining other variables – the need for this even much less so on 1.4), but especially should not use them in “when” expressions.

when: item.username in install\_users

much simpler!

You will notice the documentation does not make use of $foo when showing examples, so it can be a great reference.

[http://ansibleworks.com/docs/playbooks\_conditionals.html#id10](http://ansibleworks.com/docs/playbooks_conditionals.html#id10)
