Skip to content

Instantly share code, notes, and snippets.

@ArgonQQ
Forked from jgornick/ansible.yml
Created January 10, 2018 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArgonQQ/59a1b4a42e226adcc03e98d470ddd43d to your computer and use it in GitHub Desktop.
Save ArgonQQ/59a1b4a42e226adcc03e98d470ddd43d to your computer and use it in GitHub Desktop.
Ansible: Remove All Files Except
---
- 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