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’ }
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