Last active
September 27, 2024 10:20
-
-
Save lemajes/5e5cc8c11384d6e42e1760b73471c620 to your computer and use it in GitHub Desktop.
[Ansible Delete Folders And Files Wildcard] Delete folders and files wildcard method with Ansible #script #yml #ansible #delete #wildcard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- hosts: all | |
tasks: | |
- name: Ansible delete file wildcard | |
find: | |
paths: /etc/wild_card/example | |
patterns: "^he.*.txt" | |
use_regex: true | |
register: wildcard_files_to_delete | |
- name: Ansible remove file wildcard | |
file: | |
path: "{{ item.path }}" | |
state: absent | |
with_items: "{{ wildcard_files_to_delete.files }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use the below Ansible task to delete the wildcard folders:
The above example will find all the directories starting with '2019-' name under the '/opt/' location and delete them.