Skip to content

Instantly share code, notes, and snippets.

@PartTimeLegend
Created January 10, 2023 16:47
Show Gist options
  • Save PartTimeLegend/c91e881e261657be2f6d3faf80b10c97 to your computer and use it in GitHub Desktop.
Save PartTimeLegend/c91e881e261657be2f6d3faf80b10c97 to your computer and use it in GitHub Desktop.
House Keeping Temp Files
- name: House Keeping Temp Files
hosts: "all"
ignore_errors: yes
ignore_unreachable: yes
vars:
age: 3d
# vars_prompt:
tasks:
- name: Setting Facts for Hostname
set_fact:
hostname: "{{inventory_hostname}}"
- name: Print Hostname
debug:
var: hostname
- name: Find Files
win_find:
paths: [ "C:\\temp", "C:\\windows\\temp" ]
age: "{{ age }}"
age_stamp: mtime
recurse: yes
register: filestoremove
- name: list of files to be removed
tags: always
vars:
files: "{{ filestoremove.files | json_query('[].path') }}"
debug: var=files
when: filestoremove.matched > 0
- name: remove the files found
vars:
files: "{{ filestoremove.files | json_query('[].path') }}"
win_file:
path: "{{ item }}"
state: absent
with_items:
- "{{files}}"
when: filestoremove.matched > 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment