# Conditional expression must evaluate to True or False

**URL:** <https://forum.ansible.com/t/conditional-expression-must-evaluate-to-true-or-false/13587>\
**Category:** Ansible Project\
**Created:** [October 1, 2013, 12:18pm UTC](https://forum.ansible.com/t/conditional-expression-must-evaluate-to-true-or-false/13587 "2013-10-01T12:18:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michal\_Till](https://avatars.discourse-cdn.com/v4/letter/m/ac91a4/32.png) [@Michal\_Till](https://forum.ansible.com/u/Michal_Till)\
**Post date:** [October 1, 2013, 12:18pm UTC](https://forum.ansible.com/t/conditional-expression-must-evaluate-to-true-or-false/13587/1 "2013-10-01T12:18:32Z")

</div>

Hello,

in a play file I have a test for current node.js version:

- name: Node.js | Checking installed version of node.js  
action: shell /usr/bin/test “$(node -v 2\> /dev/null)” = v${node\_version}  
register: wanted\_version\_installed  
ignore\_errors: True

and later I skip some tasks by using when\_failed like this:

- name: Node.js | Fetching node.js source  
action: get\_url url=[http://nodejs.org/dist/v${node\_version}/${node\_tarball}](http://nodejs.org/dist/v$%7Bnode_version%7D/$%7Bnode_tarball%7D) dest=/tmp/  
when\_failed: $wanted\_version\_installed

However all I get is:

fatal: [192.168.111.222] =\> Conditional expression must evaluate to True or False: is\_failed($wanted\_version\_installed)

How should I rewrite it?

Regards,  
Michal

---

<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 1, 2013, 2:07pm UTC](https://forum.ansible.com/t/conditional-expression-must-evaluate-to-true-or-false/13587/2 "2013-10-01T14:07:59Z")

</div>

when\_failed is pretty old syntax, you should do this:

when: wanted\_version\_installed | failed

or just

when: wanted\_version\_installed.rc != 0

Also you should not use ${ node\_version } as that’s also old variable syntax that will be going away.

Use {{ node\_version }}

Though that won’t cause an error, it’s important that everyone standardize for when the old form is not available.

Plus, it’s clear to read with all of the $( shell stuff you have mixed around.

---

<div class="post-metadata">

**Author:** ![Michal\_Till](https://avatars.discourse-cdn.com/v4/letter/m/ac91a4/32.png) [@Michal\_Till](https://forum.ansible.com/u/Michal_Till)\
**Post date:** [October 1, 2013, 6:22pm UTC](https://forum.ansible.com/t/conditional-expression-must-evaluate-to-true-or-false/13587/3 "2013-10-01T18:22:31Z")

</div>

Thanks a lot for the input.

I found the recepie just googling “ansible nodejs” ([https://github.com/aenglund/nodejs-ansible/blob/master/nodejs/tasks/setup.yml](https://github.com/aenglund/nodejs-ansible/blob/master/nodejs/tasks/setup.yml))

M.

---

<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 2, 2013, 11:43am UTC](https://forum.ansible.com/t/conditional-expression-must-evaluate-to-true-or-false/13587/4 "2013-10-02T11:43:28Z")

</div>

Sure.

I can’t do anything about folks with out of date content on the internet 🙂

Be sure to consult the official docs first for the way to do things.

–Michael
