Created
May 19, 2015 12:49
-
-
Save jgornick/fcee337c2806b91b94d9 to your computer and use it in GitHub Desktop.
Ansible: Remove All Files Except
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
--- | |
- 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 |
Thank you all for the comments and suggestions! I've since been removed from working with ansible so thanks for the updates 😀
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
google gave me this gist while I was searching for solution for my problem (thanks!)
I think it can be little bit improved by adding
(so the first command will become
) so it can