You are effectively overwriting the file with the contents of each host,
onto localhost.

Ultimately you will need differently named files, or do something more
complex using a template and `run_once: true` and inside the template
looping all hosts, getting their `output`, and putting it in the file.

On Mon, Mar 21, 2022 at 9:04 AM johnc <[email protected]> wrote:

> hi guys, the below playbook seems to work ok except when the ouput gets
> written to the local file, it only shows the output of one host instead of
> 2 that I was expecting.
>
> What needs to change so that I can have the output for both hosts in perf.
>
> ---
> - name: Get various nginx configuration information
>   hosts: perf
>   become: yes
>   become_user: nginx
>   vars:
>     dest_file: /root/johnc/nginx-servers/yamloutputfile.txt
>
>   tasks:
>   - name: Get nginx config information
>     shell: |
>        hostname
>        cat /etc/logrotate.d/nginx
>        cat /etc/logrotate.conf
>        ls -al /etc/cron.daily/logrotate
>        cat /var/lib/logrotate/logrotate.status
>     register: output
>
>
>   - name: Save the output to a local file
>     become: yes
>     become_user: root
>     local_action: copy content="{{ output.stdout_lines|join('\n') }}"
> dest="{{ dest_file }}"
>
> --
> 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/fae6d8d3-3a46-41ef-adaf-b4ad6b641441n%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/fae6d8d3-3a46-41ef-adaf-b4ad6b641441n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
Matt Martz
@sivel
sivel.net

-- 
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/CAD8N0v87GRyeRQHqor7r-ViL8-O2oL2WHTAA3YLCapxz3onnuw%40mail.gmail.com.

Reply via email to