Ansible 查找并删除 JDK 文件夹

Ansible 查找并删除 JDK 文件夹

我们有路径和里面不同的文件夹

adobe_tools_path: "/apps/cq5/tools/"

是否可以通过循环仅删除 *JDK 模式文件夹?

我的剧本不符合 JDK 文件夹的模式

- name: Find JDK folders
  find:
    paths: "{{ adobe_tools_path }}"
    patterns: "*jdk"
  register: wildcard_folders_to_delete

- name: Remove file JDK wildcard
  file:
    path: "{{ item.path }}"
    state: absent
  loop: "{{ wildcard_folders_to_delete.files |flatten(levels=1) }}"

答案1

尝试使用recurse

  - name: Find JDK folders
    find:
      paths: "{{ adobe_tools_path }}"
      patterns:  "*jdk"
      file_type: directory
      recurse:   yes
    register:  jdk_folders_to_delete

  - name:  Remove unneeded JDK folders
    file:
      dest:  "{{ item.path }}"
      state: absent
    loop:  "{{ jdk_folders_to_delete.files }}"

相关内容