Skip to content

Instantly share code, notes, and snippets.

@Nothing4You
Forked from jgornick/ansible.yml
Created June 8, 2018 18:57
Show Gist options
  • Save Nothing4You/35d4942193fdf4fbdfee89e0c3c115ca to your computer and use it in GitHub Desktop.
Save Nothing4You/35d4942193fdf4fbdfee89e0c3c115ca 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