-
-
Save Nothing4You/35d4942193fdf4fbdfee89e0c3c115ca to your computer and use it in GitHub Desktop.
Ansible: Remove All Files Except
This file contains 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
--- | |
- name: Capture files in path and register | |
shell: > | |
ls -1 /path/to/files | |
register: files | |
- name: Remove files except specified | |
file: | |
path: "/path/to/files/{{ item }}" | |
state: absent | |
with_items: files.stdout_lines | |
when: > | |
item not in list_of_files_to_keep |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment