Hi,
I’ve got the following structures (or at least I’m hoping to be able to use them)
`
list_of_files:
- { filename: file1, version: 1 }
- { filename: file2, version: 1 }
- { filename: file3, version: 1 }
- { filename: file1, version: 2 }
- { filename: file2, version: 2 }
- { filename: file1, version: 3 }
- { filename: file1, version: 4 }
- { filename: file1, version: 5 }
- { filename: file2, version: 5 }
dict_name:
key1:
type: x
dictversion: 1
key2:
type: y
dictversion: 2
key3:
type: z
dictversion: 1
`
I’d like to use dict_name.key.dictversion to download all files from list_of_files where dict_name.keyX.dictversion==list_of_files.version.
Meaning, for each key, I’d like to get the (variable) number of files with the versionnumber that specific key has.
I tried with this:
`
- name: Get files
get_url: url={{ source }}/{{ item.0.filename }} dest={{ somewhere }}
with_together: - dict_name
- list_of_files
when: “{{ dict_name[item.1].dictversion }}” == "{{ item.0.version }}
`
But it doesnt work. It errors out with a stacktrace:
File “/usr/lib/python2.7/site-packages/ansible/runner/init.py”, line 561, in _executor
exec_rc = self._executor_internal(host, new_stdin)
File “/usr/lib/python2.7/site-packages/ansible/runner/init.py”, line 696, in _executor_internal
complex_args=complex_args
File “/usr/lib/python2.7/site-packages/ansible/runner/init.py”, line 756, in _executor_internal_inner
if not utils.check_conditional(cond, self.basedir, inject, fail_on_undefined=self.error_on_undefined_vars):
File “/usr/lib/python2.7/site-packages/ansible/utils/init.py”, line 254, in check_conditional
conditional = template.template(basedir, conditional, inject, fail_on_undefined=fail_on_undefined)
File “/usr/lib/python2.7/site-packages/ansible/utils/template.py”, line 115, in template
varname = template_from_string(basedir, varname, vars, fail_on_undefined)
File “/usr/lib/python2.7/site-packages/ansible/utils/template.py”, line 357, in template_from_string
res = jinja2.utils.concat(rf)
File “”, line 10, in root
File “/usr/lib/python2.7/site-packages/jinja2/environment.py”, line 372, in getattr
return getattr(obj, attribute)
File “/usr/lib/python2.7/site-packages/jinja2/runtime.py”, line 463, in getattr
return self._fail_with_undefined_error()
File “/usr/lib/python2.7/site-packages/jinja2/runtime.py”, line 457, in _fail_with_undefined_error
raise self._undefined_exception(hint)
UndefinedError: dict object has no element None
Is this even possible?
I could work around this by adding something like a ‘download: true/false’ to the list and use that in the when:, but I really like the to be able to control which files to get by using the dictversion variable in dict_name
regards
/Micke