Skip to content

Instantly share code, notes, and snippets.

@talonx
Forked from jgornick/ansible.yml
Last active June 19, 2017 19:27
Show Gist options
  • Save talonx/0ee6fff9e4915ff7458a9c55035f4384 to your computer and use it in GitHub Desktop.
Save talonx/0ee6fff9e4915ff7458a9c55035f4384 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