Hello,

dyio...@gmail.com 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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/cfdb24ad-5ef9-419b-8806-9459199f7997n%40googlegroups.com.

Reply via email to