Ansible:如何删除目录中的文件和文件夹? [英] Ansible: How to delete files and folders inside a directory?

查看:70
本文介绍了Ansible:如何删除目录中的文件和文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码只删除它在 web 目录中获取的第一个文件.我想删除 web 目录中的所有文件和文件夹并保留 web 目录.我该怎么做?

The below code only deletes the first file it gets inside the web dir. I want to remove all the files and folders inside the web directory and retain the web directory. How can I do that?

- name: remove web dir contents
    file: path='/home/mydata/web/{{ item }}' state=absent
    with_fileglob:
      - /home/mydata/web/*

注意:我已经使用命令和 shell 尝试了 rm -rf,但它们不起作用.也许我用错了它们.

Note: I've tried rm -rf using command and shell, but they don't work. Perhaps I am using them wrongly.

对正确方向的任何帮助将不胜感激.

Any help in the right direction will be appreciated.

我使用的是 ansible 2.1.0.0

I am using ansible 2.1.0.0

推荐答案

- name: Delete content & directory
  file:
    state: absent
    path: /home/mydata/web/

注意:这也会删除目录.

这篇关于Ansible:如何删除目录中的文件和文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆