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

On Friday, September 17, 2021 at 1:46:14 AM UTC+5:30 [email protected] 
wrote:

> 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] 
> *************************************************************
> ---
> Thursday 16 September 2021  11:49:08 -0400 (0:00:00.059)       0:00:00.986 
> ****
> changed: [host2]
>
> TASK [print system date] 
> *******************************************************
> Thursday 16 September 2021  11:49:09 -0400 (0:00:00.965)       0:00:01.951 
> ****
> ok: [host2] => {
>     "msg": "Hostname is: host2 and System date is: Thu Sep 16 11:49:09 EDT 
> 2021"
> }
>
> PLAY RECAP 
> *********************************************************************
> ~
>
> I'd want the to look like this:
>
> PLAY [all] 
> *********************************************************************
>
> TASK [system date] 
> *************************************************************
> ---
> Thursday 16 September 2021  11:49:08 -0400 (0:00:00.059)       0:00:00.986 
> ****
> changed: [host1]
>
> Thursday 16 September 2021  11:49:07 -0400 (0:00:00.037)       0:00:00.037 
> ****
> changed: [host2]
>
> TASK [print system date] 
> *******************************************************
> 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"
> }
>
> PLAY RECAP 
> *********************************************************************
> ~
>
> Is that possible?
> On Thursday, September 16, 2021 at 3:46:29 PM UTC-4 [email protected] 
> wrote:
>
>> Hello,
>>
>> [email protected] schrieb am Donnerstag, 16. September 2021 um 20:26:27 
>> UTC+3:
>>
>>> Taking, e.g., the following simple playbook:
>>>
>>> ---
>>>
>>> - 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
>>  
>>
>

-- 
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/49650888-ea0f-4de5-95bf-17eea22953c3n%40googlegroups.com.

Reply via email to