Created
July 28, 2018 22:49
-
-
Save brandonkal/3e33b8f871db24b60e1dc65a7be9f784 to your computer and use it in GitHub Desktop.
ansible-rm-files-not-whitelisted
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: Delete files from directory not in whitelist | |
hosts: localhost | |
gather_facts: false | |
vars: | |
whitelist: | |
- a | |
- b | |
- c | |
tasks: | |
- name: Get list of items in dir | |
command: ls -1 | |
args: | |
chdir: ./files_rm | |
register: the_files | |
- name: delete files not in whitelist list | |
file: | |
path: ./files_rm/{{ item }} | |
state: absent | |
when: item not in whitelist | |
loop: "{{ the_files.stdout_lines }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment