jinja2 warning when using "failed_when" with a variable

Hello!

I have the task below, which works absolutely fine, and errors out correctly as well. However, I get a WARNING any time I run the play. (I have a variable in the failed_when line)

  • name: Disable App ‘{{ currentApp }}’
    shell: productcontrol app disable ‘{{ currentApp }}’ -f
    args:
    executable: /bin/bash
    register: app_disabled_status
    failed_when: ‘“Cannot get application information : Application {{ currentApp }} not found.” in app_disabled_status.stderr’

I get the following warning any time I run the play:
[WARNING]: when statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: “Cannot get application information : Application {{ currentApp }} not found.” in app_disabled_status.stderr

And this result, which is expected and normal:

fatal: [localhost]: FAILED! => {
“changed”: true,
“cmd”: “productcontrol app disable ‘smartanalyser_20180622.08’ -f”,
“delta”: “0:00:00.091174”,
“end”: “2018-06-28 10:54:16.624808”,
“failed_when_result”: true,
“invocation”: {
“module_args”: {
“_raw_params”: “productcontrol app disable ‘smartanalyser_20180622.08’ -f”,
“_uses_shell”: true,
“chdir”: null,
“creates”: null,
“executable”: “/bin/bash”,
“removes”: null,
“stdin”: null,
“warn”: true
}
},
“msg”: “non-zero return code”,
“rc”: 81,
“start”: “2018-06-28 10:54:16.533634”,
“stderr”: “Cannot get application information : Application smartanalyser_20180622.08 not found.”,
“stderr_lines”: [
“Cannot get application information : Application smartanalyser_20180622.08 not found.”
],
“stdout”: “”,
“stdout_lines”:
}

So when I removed the curly brackets, from the variable in the failed_when line, it still runs fine and it picks up the variable too however, it does not error when it’s supposed to and it just assumes that it’s a change.

  • name: Disable App ‘{{ currentApp }}’
    shell: productcontrol app disable ‘{{ currentApp }}’ -f
    args:
    executable: /bin/bash
    register: app_disabled_status
    failed_when: ‘“Cannot get application information : Application currentApp not found.” in app_disabled_status.stderr’

I don’t get the Warning anymore, however get this result which is not normal as it has to error out like above:

changed: [localhost] => {

“changed”: true,

“cmd”: “productcontrol app disable ‘smartanalyser_20180622.08’ -f”,

“delta”: “0:00:00.081680”,

“end”: “2018-06-28 10:53:53.515488”,

“failed_when_result”: false,

“invocation”: {

“module_args”: {

“_raw_params”: “productcontrol app disable ‘smartanalyser_20180622.08’ -f”,

“_uses_shell”: true,

“chdir”: null,

“creates”: null,

“executable”: “/bin/bash”,

“removes”: null,

“stdin”: null,

“warn”: true

}

},

“msg”: “non-zero return code”,

“rc”: 81,

“start”: “2018-06-28 10:53:53.433808”,

“stderr”: “Cannot get application information : Application smartanalyser_20180622.08 not found.”,

“stderr_lines”: [

“Cannot get application information : Application smartanalyser_20180622.08 not found.”

],

“stdout”: “”,

“stdout_lines”:

}

Would any one have an idea as to why this might be happening? is there anything incorrect with my syntax?

It works fine with the curly brackets around the variable, but I’d rather get it fixed in case the method gets deprecated in the next ansible release.

Thanks in advance!
JS

You want the following instead:

failed_when: '"Cannot get application information : Application " ~ currentApp ~ " not found." in app_disabled_status.stderr'

Thanks Matt!

That worked like a charm.