Instead of using the Ansible shell or command modules, I am trying to use the find module to delete old backup directories and only keep the latest n
backups. Currently, I use the following code to get a list of all the backup directories (so that in a second step I could delete the unwanted ones):
- find:
paths: "/opt/"
patterns: "backup_*"
file_type: "directory"
Unfortunately, I don't see any way of narrowing down the resulting list of directories...
- The find module doesn't seem to support sorting... can that be done in any way?
- Does Ansible provide any means to manipulate a JSON list... to keep only
n
elements in a list and remove all others?
Has anyone successfully used the find module for similar purposes?