{{dest_file}} only shows output of one host instead of 2 as I was expecting

10 views
Skip to first unread message

johnc

unread,
Mar 21, 2022, 10:04:56 AM3/21/22
to Ansible Project
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 }}"

Matt Martz

unread,
Mar 21, 2022, 11:40:16 AM3/21/22
to ansible...@googlegroups.com
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.

--
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-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/fae6d8d3-3a46-41ef-adaf-b4ad6b641441n%40googlegroups.com.


--
Matt Martz
@sivel
sivel.net
Reply all
Reply to author
Forward
0 new messages