# Aggregating debug msg output

**URL:** <https://forum.ansible.com/t/aggregating-debug-msg-output/35750>\
**Category:** Ansible Project\
**Created:** [September 16, 2021, 5:26pm UTC](https://forum.ansible.com/t/aggregating-debug-msg-output/35750 "2021-09-16T17:26:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dyioulos](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dyioulos/32/8363_2.png) [@dyioulos](https://forum.ansible.com/u/dyioulos)\
**Post date:** [September 16, 2021, 5:26pm UTC](https://forum.ansible.com/t/aggregating-debug-msg-output/35750/1 "2021-09-16T17:26:27Z")

</div>

Taking, e.g., the following simple playbook:

---

<div class="post-metadata">

**Author:** ![rolandm](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/rolandm/32/755_2.png) [@rolandm](https://forum.ansible.com/u/rolandm)\
**Post date:** [September 16, 2021, 7:46pm UTC](https://forum.ansible.com/t/aggregating-debug-msg-output/35750/2 "2021-09-16T19:46:29Z")

</div>

Hello,

> * * *
> 
> - hosts: all  
> gather\_facts: false  
> serial: 1
> 
> tasks:
> 
> - name: system date  
> command: date  
> register: date\_out
> 
> - name: print system date  
> debug:  
> msg: “Hostname is: {{ inventory\_hostname }} and System date is: {{ date\_out.stdout\_lines[0] }}”
> 
> Rather than the msg output is interspersed thoughout, I’d like to aggregate all of the debug messages from the various hosts into consecutive lines, like this:
> 
> ok: [host1] =\> (item=Thu Sep 16 12:41:03 EDT 2021) =\> {  
> “msg”: “Hostname is: host1 and System date is: Thu Sep 16 12:41:03 EDT 2021”  
> }
> 
> ok: [host2] =\> (item=Thu Sep 16 12:41:03 EDT 2021) =\> {  
> “msg”: “Hostname is: host2 and System date is: Thu Sep 16 12:41:03 EDT 2021”  
> }
> 
> I hope I’m clear on my ask. Is this possible and, if so, how do I do it?
> 
> Thanks!

Not sure whether I’ll got the point. However, using a template file you could collect the fact sysdate on every host and print the hostname and all sysdate in a task delegated to localhost.

… additions to playbook …

- set\_fact: sysdate={{ date\_out.stdout\_lines[0] }}

- name: dump to /tmp/DUMP  
template:  
src: dump.j2  
dest: /tmp/DUMP  
delegate\_to: localhost

Template named “dump.j2” as referred in playbook. It’s located in same directory as the playbook.

{% for host in ansible\_play\_hosts %}  
Hostname is: {{ host }} and System date is: {{ sysdate }}  
{% endfor %}

There is also a possibility to loop over the hosts in a delegated\_to task, but I don’t remember the syntax at the moment.

BR,  
Roland

---

<div class="post-metadata">

**Author:** ![dyioulos](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dyioulos/32/8363_2.png) [@dyioulos](https://forum.ansible.com/u/dyioulos)\
**Post date:** [September 16, 2021, 8:16pm UTC](https://forum.ansible.com/t/aggregating-debug-msg-output/35750/3 "2021-09-16T20:16:13Z")

</div>

Thanks, Roland. The fact is, I’d like to “aggregate” (for lack of a better term) any debug msg output, regardless of what information the playbook is trying to gather. The one I posted above is for descriptive purposes. Rather than have output of the playbook look like this:

PLAY [all] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [system date] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
Thursday 16 September 2021 11:49:07 -0400 (0:00:00.037) 0:00:00.037 \*\*\*\*  
changed: [host1]

TASK [print system date] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
Thursday 16 September 2021 11:49:08 -0400 (0:00:00.889) 0:00:00.927 \*\*\*\*  
ok: [host1] =\> {  
“msg”: “Hostname is: host1 and System date is: Thu Sep 16 11:49:08 EDT 2021”  
}

PLAY [all] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [system date] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

---

<div class="post-metadata">

**Author:** ![Pushparaj\_Gothandam](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/pushparaj_gothandam/32/5538_2.png) [@Pushparaj\_Gothandam](https://forum.ansible.com/u/Pushparaj_Gothandam)\
**Post date:** [September 17, 2021, 4:34am UTC](https://forum.ansible.com/t/aggregating-debug-msg-output/35750/4 "2021-09-17T04:34:15Z")

</div>

Save all your output to the file and assemble it using assemble module.

---

<div class="post-metadata">

**Author:** ![Oskar\_Almlov](https://avatars.discourse-cdn.com/v4/letter/o/34f0e0/32.png) [@Oskar\_Almlov](https://forum.ansible.com/u/Oskar_Almlov)\
**Post date:** [September 17, 2021, 6:05am UTC](https://forum.ansible.com/t/aggregating-debug-msg-output/35750/5 "2021-09-17T06:05:43Z")

</div>

If I’m correctly understanding what it is you want I suggest that you look into the “throttle” keyword. It can be used for serial like behavior but on individual tasks or blocks.

//Oskar
