Save debug output to local file

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}

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.

Hi Dick Visser,

Can you explain little more on this ( accumulate the results during the playbook ) , sorry I may not understand it . but from your notes , yes the copy task to file mentioned at the end of the playbook.