Using composite "when:" in Ansible 1.2.2

Hi,

is it possible to use a composite “when” expression in Ansible 1.2.2?

I’ve been trying to make a conditional task based on 2 conditions, one is a variable defined in the inventory file just for one machine, and the other one is the result of a shell module (check if the return value is not an empty string)

when: $IS_MASTER and pid_list.stdout != ‘’

But I’m getting this result:

TASK: [-----------] **********************
fatal: [xxx.xx.xx.103] => Conditional expression must evaluate to True or False: {% if True and pid_list.stdout != ‘’ %} True {% else %} False {% endif %}
fatal: [xxx.xx.xx.104] => Conditional expression must evaluate to True or False: {% if False and pid_list.stdout != ‘’ %} True {% else %} False {% endif %}

If I use only one expression, it works fine: when: $pid_list.stdout != ‘’
I cannot afford in this moment to migrate to a newer version of Ansible.

Thanks in advance.

Jean Paul Manjarres Correal.

Yeah, so 1.2.2 is two versions back.

1.3 and 1.4 have both released.

In 1.3 and 1.4, you would write this statement as "when: ‘IS_MASTER and pid_list.stdout != “”’

as you would not need the dollar signs.

I’d strongly recommend upgrading to 1.4 so you get the 4+ months of bugfixes and other improvements.

Thanks Michael!,

Thank you for your quick response and your advice.

In 1.2.2 I had to write like this:
when: IS_MASTER == ‘True’ and pid_list.stdout != ‘’

for some reason the variable wasn’t working as a boolean.

Anyways, I’ll advice my boss to upgrade to Ansible 1.4.

Thank you again, Ansible is really an excelent tool.

Jean Paul Manjarres C.