# when defined not working with hash

**URL:** <https://forum.ansible.com/t/when-defined-not-working-with-hash/20028>\
**Category:** Ansible Project\
**Created:** [December 16, 2015, 11:35am UTC](https://forum.ansible.com/t/when-defined-not-working-with-hash/20028 "2015-12-16T11:35:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jepper](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@jepper](https://forum.ansible.com/u/jepper)\
**Post date:** [December 16, 2015, 11:35am UTC](https://forum.ansible.com/t/when-defined-not-working-with-hash/20028/1 "2015-12-16T11:35:15Z")

</div>

I need to do something like this in a role, and I use an endpoint for some of the items in the hash I feed it

shell: dosomething.sh {{ item.endpoint }}  
when: “{{ item.endpoint }} is defined”

with\_items: {{ myhash }}

myhash:

- { version: ‘{{ cqrs\_version }}’ }
- { version: ‘{{ staging\_version }}’, endpoint: ‘[http://localhost:8080/staging](http://localhost:8080/staging)’ }

It breaks as follows:

TASK: [gavdeploy | wait for endpoints to become available] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [ststxdapbe02] =\> Traceback (most recent call last):  
File “/usr/local/Cellar/ansible/1.9.3/libexec/lib/python2.7/site-packages/ansible/runner/ **init**.py”, line 586, in \_executor  
exec\_rc = self.\_executor\_internal(host, new\_stdin)  
File “/usr/local/Cellar/ansible/1.9.3/libexec/lib/python2.7/site-packages/ansible/runner/ **init**.py”, line 815, in \_executor\_internal  
complex\_args=complex\_args  
File “/usr/local/Cellar/ansible/1.9.3/libexec/lib/python2.7/site-packages/ansible/runner/ **init**.py”, line 869, in \_executor\_internal\_inner  
if not utils.check\_conditional(cond, self.basedir, inject, fail\_on\_undefined=self.error\_on\_undefined\_vars):  
File “/usr/local/Cellar/ansible/1.9.3/libexec/lib/python2.7/site-packages/ansible/utils/ **init**.py”, line 265, in check\_conditional  
conditional = template.template(basedir, conditional, inject, fail\_on\_undefined=fail\_on\_undefined)  
File “/usr/local/Cellar/ansible/1.9.3/libexec/lib/python2.7/site-packages/ansible/utils/template.py”, line 122, in template  
varname = template\_from\_string(basedir, varname, templatevars, fail\_on\_undefined)  
File “/usr/local/Cellar/ansible/1.9.3/libexec/lib/python2.7/site-packages/ansible/utils/template.py”, line 371, in template\_from\_string  
res = jinja2.utils.concat(rf)  
File “”, line 8, in root  
File “/usr/local/Cellar/ansible/1.9.3/libexec/vendor/lib/python2.7/site-packages/jinja2/runtime.py”, line 489, in \_fail\_with\_undefined\_error  
raise self.\_undefined\_exception(hint)  
UndefinedError: ‘dict object’ has no attribute ‘endpoint’

FATAL: all hosts have already failed – aborting

---

<div class="post-metadata">

**Author:** ![jepper](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@jepper](https://forum.ansible.com/u/jepper)\
**Post date:** [December 16, 2015, 2:01pm UTC](https://forum.ansible.com/t/when-defined-not-working-with-hash/20028/2 "2015-12-16T14:01:04Z")

</div>

figured it out. Simply

when: “item.endpoint is defined”
