# "Dirty" find printout question

**URL:** <https://forum.ansible.com/t/dirty-find-printout-question/38732>\
**Category:** Ansible Project\
**Created:** [March 26, 2024, 10:35pm UTC](https://forum.ansible.com/t/dirty-find-printout-question/38732 "2024-03-26T22:35:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_Wanderley](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/alex_wanderley/32/3232_2.png) [@Alex\_Wanderley](https://forum.ansible.com/u/Alex_Wanderley)\
**Post date:** [March 26, 2024, 10:35pm UTC](https://forum.ansible.com/t/dirty-find-printout-question/38732/1 "2024-03-26T22:35:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [March 26, 2024, 10:37pm UTC](https://forum.ansible.com/t/dirty-find-printout-question/38732/2 "2024-03-26T22:37:11Z")

</div>

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](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_loops.html#limiting-loop-output-with-label)

---

<div class="post-metadata">

**Author:** ![Alex\_Wanderley](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/alex_wanderley/32/3232_2.png) [@Alex\_Wanderley](https://forum.ansible.com/u/Alex_Wanderley)\
**Post date:** [March 26, 2024, 10:43pm UTC](https://forum.ansible.com/t/dirty-find-printout-question/38732/3 "2024-03-26T22:43:21Z")

</div>

Thanks for the quick reply, Matt…!

I’ll take a look at that…

Alex

---

<div class="post-metadata">

**Author:** ![Alex\_Wanderley](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/alex_wanderley/32/3232_2.png) [@Alex\_Wanderley](https://forum.ansible.com/u/Alex_Wanderley)\
**Post date:** [March 26, 2024, 11:16pm UTC](https://forum.ansible.com/t/dirty-find-printout-question/38732/4 "2024-03-26T23:16:39Z")

</div>

Yes, it worked like a charm by going with:

- name: print collection result  
ansible.builtin.debug:  
msg: “{{ item.path }}”  
loop: “{{ log\_search.files }}”  
loop\_control:  
label: “{{ item.path }}”

Again, thanks a lot!

Alex

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [March 27, 2024, 7:52am UTC](https://forum.ansible.com/t/dirty-find-printout-question/38732/5 "2024-03-27T07:52:44Z")

</div>

It may be easier and less noisy to pick the path attribute and drop the loop altogether:

- name: print collection result  
ansible.builtin.debug:  
msg: “{{ log\_search.files | map(attribute=‘path’) }}”

---

<div class="post-metadata">

**Author:** ![Alex\_Wanderley](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/alex_wanderley/32/3232_2.png) [@Alex\_Wanderley](https://forum.ansible.com/u/Alex_Wanderley)\
**Post date:** [March 27, 2024, 3:37pm UTC](https://forum.ansible.com/t/dirty-find-printout-question/38732/6 "2024-03-27T15:37:49Z")

</div>

Yup, a more concise way and worked the same…!

Thanks for that, Dick!
