How do I reduce the debug output to just the message with this playbook ?

`

catalina-inspect.yml

  • name: find tomcat logs size
    hosts: tomcat
    become: no
    tasks:

  • name: finding files task
    find:
    path: .
    file_type: directory
    patterns: “tomcat-*”
    register: find
    changed_when: False

  • name: size
    shell: du -h “{{ item }}/logs” | awk ‘{print $1}’
    loop: “{{ find.files |map(attribute=‘path’)|list }}”
    register: size

  • debug:
    msg: “{{ item.item }}/logs = {{ item.stdout }}”
    loop: “{{ size.results }}”
    `

Is there a better way to handle the debug output so that I am only seeing the msg portion ?

Ansible is not a reporting tool, so if that is what you are looking for you probably need some other tool.
That being said you have many callback plugins to choose[1] and if non of them suites your need to can always create you own.

[1] https://docs.ansible.com/ansible/2.7/plugins/callback.html#plugin-list

Yes: https://docs.ansible.com/ansible/latest/plugins/callback/default.html

Apparently I couldn’t delete my comment fast enough. Thanks guys.

Ultimately the output doesn’t matter as this is just a single task in a much larger play, but I was just curious what the standard practices are and how to manipulate the output.

`

TASK [debug] *********************************************************************************************************************************************************************************
ok: [as2] => (item={‘_ansible_parsed’: True, ‘stderr_lines’: , u’changed’: True, u’stdout’: u’189G’, ‘_ansible_item_result’: True, u’delta’: u’0:00:00.014604’, ‘stdout_lines’: [u’189G’], ’
_ansible_item_label’: u’tomcat-as2’, u’end’: u’2019-07-27 12:33:45.592563’, ‘_ansible_no_log’: False, ‘failed’: False, u’cmd’: u’du -h “tomcat-as2/logs” | awk '{print $1}'‘, ‘item’: u’tomc
at-as2’, u’stderr’: u’‘, u’rc’: 0, u’invocation’: {u’module_args’: {u’warn’: True, u’executable’: None, u’_uses_shell’: True, u’_raw_params’: u’du -h “tomcat-as2/logs” | awk '{print $1}'‘,
u’removes’: None, u’argv’: None, u’creates’: None, u’chdir’: None, u’stdin’: None}}, u’start’: u’2019-07-27 12:33:45.577959’, ‘_ansible_ignore_errors’: None}) => {
“msg”: “tomcat-as2/logs = 189G”
}
ok: [as2] => (item={‘_ansible_parsed’: True, ‘stderr_lines’: , u’changed’: True, u’stdout’: u’31G’, ‘_ansible_item_result’: True, u’delta’: u’0:00:00.016055’, ‘stdout_lines’: [u’31G’], ‘_a
nsible_item_label’: u’tomcat-gw2’, u’end’: u’2019-07-27 12:33:45.961107’, ‘_ansible_no_log’: False, ‘failed’: False, u’cmd’: u’du -h “tomcat-gw2/logs” | awk '{print $1}'‘, ‘item’: u’tomcat
-gw2’, u’stderr’: u’‘, u’rc’: 0, u’invocation’: {u’module_args’: {u’warn’: True, u’executable’: None, u’_uses_shell’: True, u’_raw_params’: u’du -h “tomcat-gw2/logs” | awk '{print $1}'‘, u
‘removes’: None, u’argv’: None, u’creates’: None, u’chdir’: None, u’stdin’: None}}, u’start’: u’2019-07-27 12:33:45.945052’, ‘_ansible_ignore_errors’: None}) => {
“msg”: “tomcat-gw2/logs = 31G”
}
ok: [as2] => (item={‘_ansible_parsed’: True, ‘stderr_lines’: , u’changed’: True, u’stdout’: u’2.3G’, ‘_ansible_item_result’: True, u’delta’: u’0:00:00.013730’, ‘stdout_lines’: [u’2.3G’], ’
_ansible_item_label’: u’tomcat-staging’, u’end’: u’2019-07-27 12:33:46.283170’, ‘_ansible_no_log’: False, ‘failed’: False, u’cmd’: u’du -h “tomcat-staging/logs” | awk '{print $1}'‘, ‘item’
: u’tomcat-staging’, u’stderr’: u’‘, u’rc’: 0, u’invocation’: {u’module_args’: {u’warn’: True, u’executable’: None, u’_uses_shell’: True, u’_raw_params’: u’du -h “tomcat-staging/logs” | awk
'{print $1}'‘, u’removes’: None, u’argv’: None, u’creates’: None, u’chdir’: None, u’stdin’: None}}, u’start’: u’2019-07-27 12:33:46.269440’, ‘_ansible_ignore_errors’: None}) => {
“msg”: “tomcat-staging/logs = 2.3G”
}
ok: [as2] => (item={‘_ansible_parsed’: True, ‘stderr_lines’: , u’changed’: True, u’stdout’: u’131G’, ‘_ansible_item_result’: True, u’delta’: u’0:00:00.013226’, ‘stdout_lines’: [u’131G’], ’
_ansible_item_label’: u’tomcat-as7’, u’end’: u’2019-07-27 12:33:46.656400’, ‘_ansible_no_log’: False, ‘failed’: False, u’cmd’: u’du -h “tomcat-as7/logs” | awk '{print $1}'‘, ‘item’: u’tomc
at-as7’, u’stderr’: u’‘, u’rc’: 0, u’invocation’: {u’module_args’: {u’warn’: True, u’executable’: None, u’_uses_shell’: True, u’_raw_params’: u’du -h “tomcat-as7/logs” | awk '{print $1}'‘,
u’removes’: None, u’argv’: None, u’creates’: None, u’chdir’: None, u’stdin’: None}}, u’start’: u’2019-07-27 12:33:46.643174’, ‘_ansible_ignore_errors’: None}) => {
“msg”: “tomcat-as7/logs = 131G”
}

`

Tried some callback plugins. Doesn’t really work. I swear I’ve done this before, but I admittedly have not touched ansible in a while. Would filtering the loop in the the debug task in some way do what I need ?

https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html#limiting-loop-output-with-label