79257757

Date: 2024-12-06 11:09:16
Score: 1.5
Natty:
Report link

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

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: vitnet