Ansible - Log stdout lines from each remote host to a single file on the local server -


is there easy way log output multiple remote hosts single file on server running ansible-playbook?

i have variable called validate stores output of command executed on each server. want take validate.stdout_lines , drop lines each host 1 file locally.

here 1 of snippets wrote did not work:

- name: write results logfile   blockinfile:     create: yes     path: "/var/log/ansible/log"     insertafter: bof     block: "{{ validate.stdout }}"   delegate_to: localhost 

when executed playbook w/ above, able capture output 1 of remote hosts. want capture lines all hosts in single /var/log/ansible/log file.

one thing should add marker blockinfile wrap result each single host in unique block.

the second problem tasks run in parallel (even delegate_to: localhost, because loop here realised ansible engine) 1 task overwriting other's /var/log/ansible/log file.

as quick workaround can serialise whole play:

- hosts: ...   serial: 1    tasks:     - name: write results logfile       blockinfile:         create: yes         path: "/var/log/ansible/log"         insertafter: bof         block: "{{ validate.stdout }}"         marker: "# {{ inventory_hostname }} {mark}"       delegate_to: localhost 

the above produces intended result, if serial execution problem, might consider writing own loop single task (for ideas refer support "serial" on individual task #12170).


speaking of other methods, in 2 tasks: can concatenate results single list (no issue parallel execution then, pay attention delegated facts) , write file using copy module (see write variable file in ansible).


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -