On 03. aug. 2017 21:18, [email protected] wrote:
capture their report via stdout, and add the reports to a single local file via
local_action. sometimes this works, and sometimes it does not. in all cases i
can see that the report is generated (stdout for each target shows on the
ansible controller during task execution). but sometimes all output for a given
target is missing from the local logfile. here is the playbook:

---
- hosts: all

   tasks:
       - name: run report
         script: pkgReport.py {{ inventory_hostname }}
         register: report

       - name: build local report
         lineinfile:
             path: "/tmp/pkgReport.txt"
             insertafter: EOF
             line: "{{ item }}"
             state: present
             create: yes
         with_items: "{{ report.stdout.lines }}"
         delegate_to: 127.0.0.1


so first question ... can someone point out what i may be doing wrong?
and of course next question ... what is the smartest way of doing this?

Lets say you have 20 host, then you would have 20 task trying to write to the same file at once(or at least 5 at a time with default, because forks is default set to 5), this will seldom if at all work.

You can use assemble or the template module, personally I would use the template.

local_report.j2
---------------
{% for item in ansible_play_hosts %}
Report for host {{ item }}:
{{ hostvars[item].report.stdout }}
{% endfor %}

And a task to create the file:
- name: build local report
  template:
    src: local_report.j2
    dest: /tmp/pkgReport.txt
  run_once: true
  delegate_to: localhost

--
Kai Stian Olstad

--
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/c0b29cb4-e286-1ebf-5d04-004011c98754%40olstad.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to