【问题标题】:Ansible : delete all files and directories inside a folder and not the folder itselfAnsible:删除文件夹内的所有文件和目录,而不是文件夹本身
【发布时间】:2018-06-07 23:04:03
【问题描述】:

我正在尝试运行一个任务,该任务会删除我的项目文件夹的所有内容,而不删除文件夹本身:

我的文件夹 : appFolder ----contains----> file1 , file2 ... fileN , directory1 ...directoryN

我曾尝试使用 lsfileGlob ,但效果不佳。

- name: delete old version files
  file:
   path: "{{ paths }}"
   state: absent
  with_filesglob:
   - "{{paths}}deletes/*"

还带有 shell 模块(不好,因为它没有删除带有特殊字符名称的文件)

- shell: ls -1 /some/dir
  register: contents

- file: path=/some/dir/{{ item }} state=absent
  with_items: {{ contents.stdout_lines }}

更好的解决方案?

【问题讨论】:

    标签: ansible yaml ansible-2.x


    【解决方案1】:

    #18910 修复之前(state=empty 用于 dirs),我们只能找到解决方法。

    这是其中之一:

    - name: Clean build folder
      shell: cd /project/build && find -mindepth 1 -maxdepth 1 -print0 | xargs -0 rm -rf --
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-12
      • 2018-05-19
      • 1970-01-01
      • 1970-01-01
      • 2011-05-14
      • 2018-08-23
      • 2010-11-20
      相关资源
      最近更新 更多