Skip to content

Instantly share code, notes, and snippets.

@vterdunov
Created November 13, 2019 15:09
Show Gist options
  • Save vterdunov/f33bac731bef7d1e4da1f5b1f0578266 to your computer and use it in GitHub Desktop.
Save vterdunov/f33bac731bef7d1e4da1f5b1f0578266 to your computer and use it in GitHub Desktop.
remove old backuped files but keep 2 newest
- name: Find backuped files
find:
paths: /path/to/files/
patterns: file.yml.*
register: backuped_files
- debug:
msg: "{{ item.path }}"
loop: "{{ (backuped_files.files | sort(attribute='ctime',reverse=true))[2:] | list }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment