Check for two possible values of var in when_string?

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

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).

Yes that works; thanks for the help!