我需要从目录中删除文件,但我想通过 ansible 保留该文件夹。
我尝试过文件模块,结果发现该目录也被删除了。 有什么建议吗?
- name: empty dest directory
file:
state: absent
path: /path/to/directory/
预期:目录:/path/to/directory 为空,但该目录存在
实际:目录也被删除
最佳答案
为什么不先清空它,然后再创建它?
- name: empty dest directory
file:
state: absent
path: /path/to/directory/
- name: recreate directory
file:
state: directory
path: /path/to/directory/
关于Ansible - 如何清空文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55839314/