As d4nyll said, using loop
is recommened way. So here is Vor's variant with loop:
---
- hosts: localhost
gather_facts: false
vars:
objs:
- { key1: value1, key2: [ value2, value3] }
- { key1: value4, key2: [ value5, value6] }
tasks:
- name: create directories
file:
path: "{{ item.key1 }}"
state: directory
loop: "{{ objs }}"
- name: create files
file:
path: "{{ item.0.key1 }}/{{ item.1 }}"
state: touch
loop: "{{ objs | subelements('key2') }}"
Thanks to Nested loops - access property: the key item should point to a dictionary It helped to understand what exacltly should be in subelements