I have the following task in a playbook:
- name: task xyz
copy:
src=\"{{ item }}\"
dest=\"/tmp/{{ item }}\"
with_items: \"{{ y.z }}\"
The problem here is that with_items
is evaluated before when
. Actually in real scenarios you put item
in the when
conditional. See: Loops and Conditionals.
This task will work for you:
- name: task xyz
copy:
src: "{{ item }}"
dest: "/tmp/{{ item }}"
with_items: "{{ (y|default([])).z | default([]) }}"