Ansible - 如何清空文件夹

问题描述 投票:1回答:1

我需要从目录中删除文件,但我想通过ansible保留该文件夹。

我试过使用文件模块,结果发现该目录也被删除了。有什么建议吗?

    - name: empty dest directory 
      file:
        state: absent
        path: /path/to/directory/

预期:目录:/ path / to / directory为空,但目录存在

实际:目录也被删除

ansible
1个回答
0
投票

为什么不先将它清空,然后再创建它?

- name: empty dest directory 
  file:
    state: absent
    path: /path/to/directory/

- name: recreate directory 
  file:
    state: directory
    path: /path/to/directory/
© www.soinside.com 2019 - 2024. All rights reserved.