The functionality you are looking for is the `label` option of
`loop_control`:
https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_loops.html#limiting-loop-output-with-label

On Tue, Mar 26, 2024 at 5:36 PM Alex Wanderley <[email protected]>
wrote:

> 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
> --
>
>
>
> [image: Edmonton_sig_RGB_S.jpg]
>
> Alex Wanderley
>
> Application and Infrastructure Analyst II
> Server Solutions & Automation
>
> Financial and Corporate Services | Open City and Technology
>
>
>
> 780-496-4156  Office
>
> 780-819-0273  Mobile
>
>
>
> City of Edmonton
>
> Century Place, 19th Floor
>
> 9803 102A Avenue NW
>
> Edmonton AB, T5J 3A3
>
>
>
> All information contained in this email post is proprietary to the City of
> Edmonton, confidential and intended only for the addressed recipient. If
> you have received this post in error, please disregard the contents, inform
> the sender of the misdirection, and remove it from your system. The
> copying, dissemination or distribution of this email, if misdirected, is
> strictly prohibited.
>
> *The contents of this message and any attachment(s) are confidential,
> proprietary to the City of Edmonton, and are intended only for the
> addressed recipient. If you have received this in error, please disregard
> the contents, inform the sender of the misdirection, and remove it from
> your system. The copying, dissemination, or distribution of this message,
> if misdirected, is strictly prohibited.*
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CADp8UUQpNfDY02hCi_emzz_M6%2BB8-xE%3DaotbdVdSNsVPKHc7aw%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CADp8UUQpNfDY02hCi_emzz_M6%2BB8-xE%3DaotbdVdSNsVPKHc7aw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>


-- 
Matt Martz
@sivel
sivel.net

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAD8N0v-kUkvgdNLqj7qDa3yy87YxhgbLkTw8yGcwN5Jph9xg6g%40mail.gmail.com.

Reply via email to