Conditional expression must evaluate to True or False

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:

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

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.

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)

M.

Sure.

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

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

–Michael