Hello,
We have a simple/working playbook that looks for log files based on the server’s name and prints the file(s) it could find:
vars:
log_files: “/path/to/directory”
tasks:
-
name: Collect log files
ansible.builtin.find:
path: “{{ log_files }}/”
patterns: “{{ inventory_hostname }}”
register: log_search -
name: print collection result
ansible.builtin.debug:
msg: “{{ item.path }}”
with_items: “{{ log_search.files }}”
For each file found, the the printout looks like this:
ok: [SERVER_NAME] => (item={‘path’: ‘/path/to/directory/logs/monitor-<SERVER_NAME>-02-2024.03.18.log’, ‘mode’: ‘0644’,
‘isdir’: False, ‘ischr’: False, ‘isblk’: False, ‘isreg’: True, ‘isfifo’: False, ‘islnk’: False, ‘issock’: False, ‘uid’: 999, ‘gid’: 999,
‘size’: 272091, ‘inode’: 12956486, ‘dev’: 45, ‘nlink’: 1, ‘atime’: 1710905864.848738, ‘mtime’: 1710827942.815553, ‘ctime’: 1710827942.815553,
‘gr_name’: ‘xxxxx’, ‘pw_name’: ‘xxxxx’, ‘wusr’: True, ‘rusr’: True, ‘xusr’: False, ‘wgrp’: False, ‘rgrp’: True, ‘xgrp’: False, ‘woth’: False,
‘roth’: True, ‘xoth’: False, ‘isuid’: False, ‘isgid’: False}) => {
“msg”: “/path/to/directory/logs/monitor-<SERVER_NAME>-02-2024.03.18.log”
}
How could I, if even possible, format the printout so it would only show the whole path to the file, omitting/discarding all the other file attributes information?
(And please forgive my ignorance…)
Thanks a lot,
Alex