I'm trying to get the parent directory Name of files identified by a pattern.
base/tool1/sub/test.log
base/tool2/abc/values.log
base/tool3/sub/test.log
I want to get every directory absolute path, where test.log is to find.
so base/tool1/sub/
and base/tool3/sub/
would be the matches I want to get as result.
- name: "Loop-Playbook"
hosts: all
tasks:
- name: "Filter File Matches"
find:
paths: "/base"
file_type: "file"
recurse: "yes"
patterns: "*test.log"
register: files_matched
- name: "Debug files_matched full"
debug:
var: files_matched.files
- name: "Debug files_matched items"
debug:
var: item.path | dirname
loop: "{{ files_matched.files| flatten(levels=1) }}"
loop_control:
label: "{{ item.path }}"
I guess, I need to use something like {{ item.path | dirname }}
but to be honest I've no clue WHERE I have to define this.
Can somebody help me out?