仅在存在* .web文件的情况下如何删除它们 [英] How to delete *.web files only if they exist
本文介绍了仅在存在* .web文件的情况下如何删除它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要创建Ansible剧本才能仅删除特定目录中的*.web
文件.
I need to create an Ansible playbook to delete the *.web
files in a specific directory only if the files exists.
OS:cent OS,Redhat 5x,6x.
OS : cent OS, Redhat 5x, 6x.
我尝试了以下失败的尝试:
I have tried the following with no success:
- stat: path=/opt/app/jboss/configuration/*.web
register: web
- shell: rm -rf /opt/app/jboss/configuration/*.web
when: web.stat.exists
推荐答案
@ bruce-p的答案在Ansible 2.0+中给出了弃用警告,但是新的with_fileglob提供了另一种选择:
@bruce-p's answer gives a deprecation warning with Ansible 2.0+, but the new with_fileglob gives another option:
- file: path={{ item }} state=absent
with_fileglob: /opt/app/jboss/configuration/*.web
(类似的问题删除所有包含特定内容的文件目录中的名称具有相似的答案.)
(Similar question remove all files containing a certain name within a directory has a similar answer.)
如下所述,该方法无效;这是花哨的方式"的示例:
As noted below, that won't work; here's an example of "the fancy way":
- find:
paths: /opt/app/jboss/configuration
patterns: "*.web"
register: find_results
- file:
path: "{{ item['path'] }}"
state: absent
with_items: "{{ find_results['files'] }}"
这篇关于仅在存在* .web文件的情况下如何删除它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文