# Problem with "when" statement

**URL:** <https://forum.ansible.com/t/problem-with-when-statement/31275>\
**Category:** Ansible Project\
**Created:** [September 13, 2019, 9:42am UTC](https://forum.ansible.com/t/problem-with-when-statement/31275 "2019-09-13T09:42:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MKPhil](https://avatars.discourse-cdn.com/v4/letter/m/9e8a1a/32.png) [@MKPhil](https://forum.ansible.com/u/MKPhil)\
**Post date:** [September 13, 2019, 9:42am UTC](https://forum.ansible.com/t/problem-with-when-statement/31275/1 "2019-09-13T09:42:14Z")

</div>

I’m trying to compare two variables in a “when” statement - when x = y do something.

This code works:

`when: unit_number == {{ disk_unit }}`

BUT I get a warning:

`[WARNING]: conditional statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: unit_number == {{ disk_unit }}`

If I remove the {{ }} the statement no longer works. How should I write the statement so it works and doesn’t give the warning? I’ve tried various combinations of double and single quotes and round brackets.

---

<div class="post-metadata">

**Author:** ![shivharsh.nec](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@shivharsh.nec](https://forum.ansible.com/u/shivharsh.nec)\
**Post date:** [September 13, 2019, 11:44am UTC](https://forum.ansible.com/t/problem-with-when-statement/31275/2 "2019-09-13T11:44:39Z")

</div>

Hey,

This is a genuine warning and was added to the 2.3 release purposefully.  
You don’t need to use any special character at all and it will get rid of the warning.

Simply, use the when statement as below:

`

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [September 13, 2019, 11:57am UTC](https://forum.ansible.com/t/problem-with-when-statement/31275/3 "2019-09-13T11:57:49Z")

</div>

What does “no longer works” mean? What did you expect, what did you get?

The warning is correct - you should not use the braces in a when statement.

I’m not sure, but it sounds a bit as if the things you are comparing do not contain the values you think they do…

Regards, K.

---

<div class="post-metadata">

**Author:** ![MKPhil](https://avatars.discourse-cdn.com/v4/letter/m/9e8a1a/32.png) [@MKPhil](https://forum.ansible.com/u/MKPhil)\
**Post date:** [September 13, 2019, 12:28pm UTC](https://forum.ansible.com/t/problem-with-when-statement/31275/4 "2019-09-13T12:28:36Z")

</div>

> I’m not sure, but it sounds a bit as if the things you are comparing do not contain the values you think they do…

That was the problem! Even though both variables looked like ints when displayed with debug one or other of them wasn’t. I explicitly converted them to int and it now works

`  
when: item.unit\_number|int == disk\_unit|int

`
