# jinja2 warning when using "failed\_when" with a variable

**URL:** <https://forum.ansible.com/t/jinja2-warning-when-using-failed-when-with-a-variable/27895>\
**Category:** Ansible Project\
**Created:** [June 28, 2018, 10:22am UTC](https://forum.ansible.com/t/jinja2-warning-when-using-failed-when-with-a-variable/27895 "2018-06-28T10:22:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JS11](https://avatars.discourse-cdn.com/v4/letter/j/f17d59/32.png) [@JS11](https://forum.ansible.com/u/JS11)\
**Post date:** [June 28, 2018, 10:22am UTC](https://forum.ansible.com/t/jinja2-warning-when-using-failed-when-with-a-variable/27895/1 "2018-06-28T10:22:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [June 28, 2018, 2:25pm UTC](https://forum.ansible.com/t/jinja2-warning-when-using-failed-when-with-a-variable/27895/2 "2018-06-28T14:25:19Z")

</div>

You want the following instead:

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

```

---

<div class="post-metadata">

**Author:** ![JS11](https://avatars.discourse-cdn.com/v4/letter/j/f17d59/32.png) [@JS11](https://forum.ansible.com/u/JS11)\
**Post date:** [July 2, 2018, 4:14pm UTC](https://forum.ansible.com/t/jinja2-warning-when-using-failed-when-with-a-variable/27895/3 "2018-07-02T16:14:30Z")

</div>

Thanks Matt!

That worked like a charm.
