# when: var is defined deprecated?

**URL:** <https://forum.ansible.com/t/when-var-is-defined-deprecated/22592>\
**Category:** Ansible Project\
**Created:** [September 20, 2016, 10:42am UTC](https://forum.ansible.com/t/when-var-is-defined-deprecated/22592 "2016-09-20T10:42:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pixel\_fairy](https://avatars.discourse-cdn.com/v4/letter/p/6f9a4e/32.png) [@pixel\_fairy](https://forum.ansible.com/u/pixel_fairy)\
**Post date:** [September 20, 2016, 10:42am UTC](https://forum.ansible.com/t/when-var-is-defined-deprecated/22592/1 "2016-09-20T10:42:49Z")

</div>

using ansible 2.1.1.0

running a task with ‘when: users is defined’ works fine for hosts that have that variable. for hosts that dont, the play still runs, but gives a warning that in the future, an undefined variable will be a fatal error. is there another way of running tasks based on the existence of a given var?

---

<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:** [September 20, 2016, 2:10pm UTC](https://forum.ansible.com/t/when-var-is-defined-deprecated/22592/2 "2016-09-20T14:10:29Z")

</div>

You should generally provide your full task, so I’m going to take a guess here.

I am pretty sure the problem is that you are using `with_items: users` also. The problem is that `when` statements are evaluated _after_ `with_items`, since the `when` statement is evaluated per item in the loop.

---

<div class="post-metadata">

**Author:** ![pixel\_fairy](https://avatars.discourse-cdn.com/v4/letter/p/6f9a4e/32.png) [@pixel\_fairy](https://forum.ansible.com/u/pixel_fairy)\
**Post date:** [September 20, 2016, 5:13pm UTC](https://forum.ansible.com/t/when-var-is-defined-deprecated/22592/3 "2016-09-20T17:13:45Z")

</div>

yes. used a group so the when was not needed.
