This is because the file gets overwritten for each host, and thus you
always end up with the last host.
 You need to accumulate the results during the playbook and at the end
write to file.

On Thu, 21 Jan 2021 at 18:47, Ramesh AR <[email protected]> wrote:
>
> Folks,
>
> I'm trying to copy the debug output to a local file for next task.
>
> My host inventory has 2 hosts and I see the local file has only one host 
> output.
> is something missing in playbook ? if I have 10 hosts how to get copied all 
> the output to a file.
>
> please help on this,
>
>    register: result
>   - set_fact:
>       user: "{{ result.configResolveClass.children|json_query(my_query) }}"
>     vars:
>       my_query: "[].outConfigs.children[].aaaUser.attributes[].{id: id, name: 
> name, priv: priv, accountStatus: accountStatus}"
>
>   - local_action: copy content="CIMC IP is {{ inventory_hostname.split() | 
> list | to_yaml }} {{ user | rejectattr('accountStatus', 'eq', 'inactive')| 
> list | to_yaml }}" dest=/root/user.txt
>
>
> PLAY [cimc] 
> ********************************************************************************************************************************
>
> TASK [Checking service accounts] 
> *****************************************************************************************************************
> ok: [host1]
> ok: [host2]
>
> TASK [set_fact] 
> **********************************************************************************************************************************
> ok: [host1]
> ok: [host2]
>
> TASK [copy] 
> **************************************************************************************************************************************
> changed: [host1 -> localhost]
> changed: [host2 -> localhost]
>
> PLAY RECAP 
> ***************************************************************************************************************************************
> host1            : ok=3    changed=1    unreachable=0    failed=0    
> skipped=0    rescued=0    ignored=0
> host2             : ok=3    changed=1    unreachable=0    failed=0    
> skipped=0    rescued=0    ignored=0
>
>
> cat user.txt
> CIMC IP is [host1]
>  - {accountStatus: active, id: '1', name: admin, priv: admin}
> - {accountStatus: active, id: '2', name:account1 , priv: admin}
> - {accountStatus: active, id: '3', name:account2, priv: admin}
> - {accountStatus: active, id: '4', name:account3 , priv: admin}
> - {accountStatus: active, id: '5', name:account4 , priv: admin}
> - {accountStatus: active, id: '6', name:account5 , priv: admin}
> - {accountStatus: active, id: '7', name:account6 , priv: admin}
>
> --
> 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/7f404c81-22b5-41b6-b59f-7a7b6e1f2147n%40googlegroups.com.



-- 
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

-- 
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/CAL8fbwOfiLF16TFzJQAPoMxGfMv41VyaZrapXsQz5qMHWZYMaA%40mail.gmail.com.

Reply via email to