数组上方的数组创建文件夹

我尝试将with_items*一起使用,但似乎不支持。

vars/main.yml

---
Z:
  A1:
    - "a"
    - "b"
  A2: "c"
  A3:
    - "d"
    - "e"

tasks/main.yml

---
- name: Create folder
  file:
    path: "{{ item }}"
    state: directory
    mode: '0755'
    owner: tomcat
    group: tomcat
  with_items:
    - "/opt/Z/{{ Z.A1.* }}"
    - "/opt/Z/{{ Z.A1.* }}/in"
    - "/opt/Z/{{ Z.A1.* }}/in/output/"
    - "/opt/Z/{{ Z.A1.* }}/in/output/fail"
    - "/opt/Z/{{ Z.A1.* }}/in/output/success"

我想获得以下输出,我不确定如何将with_items与array over array一起使用。

  /opt/Z/a
  /opt/Z/a/in
  /opt/Z/a/in/output/
  /opt/Z/a/in/output/fail
  /opt/Z/a/in/output/success

  /opt/Z/b
  /opt/Z/b/in
  /opt/Z/b/in/output/
  /opt/Z/b/in/output/fail
  /opt/Z/b/in/output/success
yoyocom_33 回答:数组上方的数组创建文件夹

过滤器product完成任务。例如剧本

  vars:
    Z:
      A1:
        - "a"
        - "b"
      A2:
        - "c"
      A3:
        - "d"
        - "e"
    list2:
      - ""
      - "/in"
      - "/in/output/"
      - "/in/output/fail"
      - "/in/output/success"

  tasks:
    - debug:
        msg: "/opt/Z/{{ item.0 }}{{ item.1 }}"
      loop: "{{ Z.A1|product(list2)|list }}"

给予

  msg: /opt/Z/a
  msg: /opt/Z/a/in
  msg: /opt/Z/a/in/output/
  msg: /opt/Z/a/in/output/fail
  msg: /opt/Z/a/in/output/success
  msg: /opt/Z/b
  msg: /opt/Z/b/in
  msg: /opt/Z/b/in/output/
  msg: /opt/Z/b/in/output/fail
  msg: /opt/Z/b/in/output/success
,

debug一起使用时看起来不错,但是当我将loopfile一起使用时,输出效果很差:(

- name: Create folders
  file:
    path: "/opt/Z/{{ item.0 }}{{ item.1 }}"
    state: directory
    mode: '0755'
  loop:
    - "{{ Z.A1|product(list2)|list }}"

给予

# tree
.
└── Z
    └── ['a',\ '']['a',\ '
        └── in']
本文链接:https://www.f2er.com/3154985.html

大家都在问