# Using composite "when:" in Ansible 1.2.2

**URL:** <https://forum.ansible.com/t/using-composite-when-in-ansible-1-2-2/14008>\
**Category:** Ansible Project\
**Created:** [November 26, 2013, 9:22pm UTC](https://forum.ansible.com/t/using-composite-when-in-ansible-1-2-2/14008 "2013-11-26T21:22:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jean\_Paul\_Manjarres](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@Jean\_Paul\_Manjarres](https://forum.ansible.com/u/Jean_Paul_Manjarres)\
**Post date:** [November 26, 2013, 9:22pm UTC](https://forum.ansible.com/t/using-composite-when-in-ansible-1-2-2/14008/1 "2013-11-26T21:22:01Z")

</div>

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.

---

<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:** [November 26, 2013, 9:51pm UTC](https://forum.ansible.com/t/using-composite-when-in-ansible-1-2-2/14008/2 "2013-11-26T21:51:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Jean\_Paul\_Manjarres](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@Jean\_Paul\_Manjarres](https://forum.ansible.com/u/Jean_Paul_Manjarres)\
**Post date:** [November 26, 2013, 10:40pm UTC](https://forum.ansible.com/t/using-composite-when-in-ansible-1-2-2/14008/3 "2013-11-26T22:40:27Z")

</div>

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.
