# new warning in Ansible 2.3

**URL:** <https://forum.ansible.com/t/new-warning-in-ansible-2-3/24330>\
**Category:** Ansible Project\
**Created:** [April 26, 2017, 5:23pm UTC](https://forum.ansible.com/t/new-warning-in-ansible-2-3/24330 "2017-04-26T17:23:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![PhilEv](https://avatars.discourse-cdn.com/v4/letter/p/ee59a6/32.png) [@PhilEv](https://forum.ansible.com/u/PhilEv)\
**Post date:** [April 26, 2017, 5:23pm UTC](https://forum.ansible.com/t/new-warning-in-ansible-2-3/24330/1 "2017-04-26T17:23:19Z")

</div>

The warning is:

[WARNING]: when statements should not include jinja2 templating delimiters such as {{ }} or {% %}.

Not sure how to avoid it in the below case. Any hint ?

See [https://github.com/ansible/ansible/issues/22397](https://github.com/ansible/ansible/issues/22397). Sorry for commenting in a closed issue

consider the following variable:

```auto
to_be_removed_users:
  - name: 'adm'
    remove: False 
  - name: 'ftp'
    remove: True
  - name: 'games'
    remove: False  
  - name: 'gopher'
    remove: True
  - name: 'operator'
    remove: False
  - name: 'uucp'
    remove: True

```

then the following tasks generate the warning. Not sure how to avoid it as [item.name](http://item.name) is the result of iteration on the list

```auto
name: Get users list 
 getent: 
   database: passwd
 tags:
   - userdel

- name: Make sure the following users are removed
 user: 
   name: "{{ [item.name](http://item.name) }}"
   state: absent 
   remove: "{{item.remove}}"
 with_items: '{{ to_be_removed_users }}'
 when: getent_passwd.{{ [item.name](http://item.name) }} is defined
 tags:
   - userdel

```

---

<div class="post-metadata">

**Author:** ![Josh\_Smift1](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@Josh\_Smift1](https://forum.ansible.com/u/Josh_Smift1)\
**Post date:** [April 26, 2017, 5:28pm UTC](https://forum.ansible.com/t/new-warning-in-ansible-2-3/24330/2 "2017-04-26T17:28:44Z")

</div>

> Not sure how to avoid it in the below case. Any hint ?

I often find it helps to use the more Pythonic expression of the  
variables, thing['foo'][bar], so you can tell that 'foo' is a literal  
string and bar is a variable, rather than the sloppy thing.foo.bar, where  
you can't.

So instead of

&nbsp;&nbsp;when: getent\_passwd.{{ item.name }} is defined

try

&nbsp;&nbsp;when: getent\_passwd[item['name']] is defined

I'm not 100% sure that's the problem you're having, but if it is, does  
that work?

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-Josh (jbs@care.com)

(apologies for the automatic corporate disclaimer that follows)

This email is intended for the person(s) to whom it is addressed and may contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, distribution, copying, or disclosure by any person other than the addressee(s) is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and delete the message and any attachments from your system.

---

<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:** [April 26, 2017, 5:32pm UTC](https://forum.ansible.com/t/new-warning-in-ansible-2-3/24330/3 "2017-04-26T17:32:26Z")

</div>

Technically, while what you have there worked, it’s not recommended.

Instead what you want, is something like:

when: hostvars[inventory\_hostname][‘getent\_passwd’][[item.name](http://item.name)] is defined

Or potentially:

when: vars[‘getent\_passwd’][‘[item.name](http://item.name)’] is defined

When you use {{ }} a jinja2 statement, it can create unintended consequences, because the when statement and the {{ }} you put in the when statement are evaluated at different times, and can actually cause Undefined errors.

---

<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:** [April 26, 2017, 5:33pm UTC](https://forum.ansible.com/t/new-warning-in-ansible-2-3/24330/4 "2017-04-26T17:33:09Z")

</div>

Yeah, or what Josh said too 🙂

---

<div class="post-metadata">

**Author:** ![PhilEv](https://avatars.discourse-cdn.com/v4/letter/p/ee59a6/32.png) [@PhilEv](https://forum.ansible.com/u/PhilEv)\
**Post date:** [April 27, 2017, 8:07am UTC](https://forum.ansible.com/t/new-warning-in-ansible-2-3/24330/5 "2017-04-27T08:07:57Z")

</div>

Thanks Matt and Josh

using the below works perfectly

> when: getent\_passwd[item[‘name’]] is defined

So this addressed the warning ansible2.3.0 was reporting and  
I also got a better understanding about why to avoid jinja in when statement

Phil
