Given the variable structure
syncjobs:
- filename: output1.bash
content: data1
- filename: output2.bash
content: data2
I want to loop over it creating the files with ansible.builtin.template using the field filename for the dest. I can achieve this with
- name: Create scripts
ansible.builtin.template:
src: template.bash.j2
dest: /opt/bin/{{ item.filename }}
owner: root
mode: "u+x,o-r"
backup: true
with_items: "{{ syncjobs }}"
however I can't figure out how to address the specific content field from the syncjobs dict in the template file. Of course I can access the variable syncjobs, but I need to address the content field from the related dictionary for every specific iteration.
I tried to set an additional fact like current_filename to item.filename inside an ansible.builtin.block, but unfortunately loops does not seem to be supported for blocks.