0
匹配特定的命名標準在ansible我需要從匹配特定的命名條件的文件夾中刪除文件,刪除文件:喜歡與ABC在ansible
開始的所有文件和文件夾要刪除/ ABC *。 *
我用下面的任務要刪除所有文件:
- name: Removes all files
file:
path: "<folder path>/root/"
state: absent
不過,我需要能夠在這裏指定一個標準的地方,只用與ABC-開始*名字刪除這些文件和文件夾。
我已經嘗試使用:
- name: Removes files that start with abc
file:
path: "{{item}}"
state: absent
with_fileglob:
- <path>/abc*
但是,這不符合任何文件/文件夾。
我也曾嘗試:
- name: Finds files and folders
find:
paths: "<path>/"
patterns: "abc*"
recurse: yes
register: result
- name: Removes files and folders
file:
path: "{{item.path}}"
state: absent
with_items: '{{result.files}}'
這也犯規返回任何文件或文件夾。
您是否可以先修復縮進並重試? 'file:'和'with_fileglob:'需要有相同的級別。你可以在這裏閱讀YAML語法的更多內容:http://docs.ansible.com/ansible/YAMLSyntax.html – xeroqu
對不起,我更正了縮進。 – trial999