On 08.03.2019 17:03, 'Chris Bidwell - NOAA Federal' via Ansible Project wrote:
> Hi all,
> 
> So I've got this playbook that is getting information from all of my hosts
> in my inventory and outputting that data to a local file.  However, it's
> not outputting on EVERY inventory host.  It's going through the list like
> it's supposed to be, but it's not putting everything in the file.  Any
> ideas?  I've got over 80 systems in my ALL_RHEL group but only get about 40
> line items in my output.txt file.

All[1] the "hosts" is trying to write to the same file at the same the same 
time, and that is causing your problem.


> Here's my playbook:
> 
> ---
> - hosts: ALL_RHEL
>    become: yes
>    vars_files:
>      - passwd.yml
>      - vars.yml
> 
>    tasks:
>      - name: Workstation or Server?
>        shell: cat /etc/redhat-release | awk '{print $5}'
>        register: rh_type
>        tags: name
> 
>      - name: Output info to output.txt
>        lineinfile:
>          dest: /tmp/output.txt
>          line: "{{ ansible_hostname }}, {{ ansible_kernel }}, {{
> rh_type.stdout }}"
>          create: yes
>          insertafter: EOF
>        delegate_to: localhost

This last task you need to run as loop with run_once so only one task is 
writing to the file.
Something like this:

    - name: Output info to output.txt
      lineinfile:
        dest: /tmp/output.txt
        line: "{{ hostvars[item].ansible_hostname }}, {{ 
hostvars[item].ansible_kernel }}, {{ hostvars[item].rh_type.stdout }}"
        create: yes
        insertafter: EOF
      delegate_to: localhost
      run_once: yes
      with_items: "{{ ansible_play_hosts }}"


[1] How may host is actually determine by fork and serial. Default it would be 
5 hosts at a time.

-- 
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/64231d7a-9185-6cd2-4d74-a35049e64a98%40olstad.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to