I want to implement some sort of rotation on subdirectories of folders in a list. Say I have dir1 and dir2, I need to go inside each of them and delete all folders older than X days in dir1 and Y days in dir2.
vars:
backups:
dir1:
name: dir1
days: 10d
dir2:
name: dir2
days: 3d
I've tried to create a task like this
- name: find all folders
find:
paths: "/home/user1/{{ item.value.name }}"
age: "{{ item.value.days }}"
file_type: directory
loop: "{{ lookup('dict', backups) }}"
register: dirsOlderThanXd
But, dirsOlderThanXd has a strange format. If there were no loop and just a single directory next step would be something like
- name: remove old folders
file:
path: "{{ item.path }}"
state: absent
with_items: "{{ dirsOlderThanXd.files }}"
Documentation says
When you use
registerwith a loop, the data structure placed in the variable will contain aresultsattribute that is a list of all responses from the module. This differs from the data structure returned when usingregisterwithout a loop.
So, it's expected, but, how exactly do I work with this output? Or am I doing it all completely wrong?