# Check for two possible values of var in when\_string?

**URL:** <https://forum.ansible.com/t/check-for-two-possible-values-of-var-in-when-string/13574>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [September 29, 2013, 6:50am UTC](https://forum.ansible.com/t/check-for-two-possible-values-of-var-in-when-string/13574 "2013-09-29T06:50:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Casey](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@Mark\_Casey](https://forum.ansible.com/u/Mark_Casey)\
**Post date:** [September 29, 2013, 6:50am UTC](https://forum.ansible.com/t/check-for-two-possible-values-of-var-in-when-string/13574/1 "2013-09-29T06:50:02Z")

</div>

Hello,

First of all many thanks for ansible to those responsible. I’m just getting started with it and am loving it.

Anyway I did a bit of searching around but can’t seem to get this to work. I want to do **_when\_string: ${var} == “this” || “that”_**

This is the task file which is being imported:

> * * *
> 
> - name: Enable OpenVZ Console (tty) - Ubuntu  
> copy: src=…/files/openvz\_tty\_ubuntu dest=/etc/init/tty1.conf  
> when\_string: ${ansible\_distribution} == “Ubuntu” && ${ansible\_distribution\_release} == ( “precise” || “lucid” )
> 
> - name: Enable OpenVZ Console (tty) - Debian  
> lineinfile: dest=/etc/inittab regexp=“^1:2345:” line=“1:2345:respawn:/sbin/getty 38400 tty1” state=present  
> when\_string: ${ansible\_distribution} == “Debian” && ${ansible\_distribution\_release} == [“lenny” || “squeeze” || “wheezy”]

I’ve tried some permutations with … ’ in [“precise”, “lucid”] ’ too but none of these are working and I can’t seem to find anything that says this is actually possible.

(and I guess while we’re here… Is it bad to check the facts directly with out an intermediate var, like I did here? Any other obvious issues?)

Thanks,  
Mark

---

<div class="post-metadata">

**Author:** ![James\_Cammarata1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@James\_Cammarata1](https://forum.ansible.com/u/James_Cammarata1)\
**Post date:** [September 29, 2013, 9:40pm UTC](https://forum.ansible.com/t/check-for-two-possible-values-of-var-in-when-string/13574/2 "2013-09-29T21:40:54Z")

</div>

Using when\_string and ${var} are the older ways of doing things, so do this instead: ‘when: ansible\_distribution\_release in [“precise”,“lucid”]’. It won’t ever be in those values if the distribution isn’t Ubuntu, so it’s quite a bit simpler too (same goes for the Debian check).

---

<div class="post-metadata">

**Author:** ![Mark\_Casey](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@Mark\_Casey](https://forum.ansible.com/u/Mark_Casey)\
**Post date:** [September 30, 2013, 6:14pm UTC](https://forum.ansible.com/t/check-for-two-possible-values-of-var-in-when-string/13574/3 "2013-09-30T18:14:05Z")

</div>

Yes that works; thanks for the help!
