Save output to text file

Hello

I have my playbook that will just execute df -h and ls -ll teh issue is that is not being able to save the output to a txt file

Hello,

Since you’re collecting your results with a loop, you’ll have several results registered in enviro variable.

enviro.results[0].stdout will point to the stdout of the first command, and so on.

Luca

Hello ,

I tried with this configuration

  • name: SAVE OUTPUT TO FILE
    copy:
    content: “{{ enviro.results[0].stdout }}”
    dest: “/root/playbooks/results/{{ inventory_hostname }}-space.txt”
    tags: save

But still having the same issue

fatal: [localhost]: FAILED! => {

“msg”: “The task includes an option with an undefined variable. The error was: ‘dict object’ has no attribute ‘stdout’\n\nThe error appears to be in ‘/root/playbooks/space_mail.yml’: line 20, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: SAVE OUTPUT TO FILE\n ^ here\n”
}

Thanks.

Hello ,

I tried with this configuration

- name: SAVE OUTPUT TO FILE
copy:
content: "{{ enviro.results[0].stdout }}"
dest: "/root/playbooks/results/{{ inventory_hostname }}-space.txt"
tags: save

But still having the same issue

fatal: [localhost]: FAILED! => {
"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute
'stdout'\n\nThe error appears to be in '/root/playbooks/space_mail.yml': line 20, column 7, but may\nbe elsewhere in the
file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: SAVE OUTPUT TO FILE\n
^ here\n"
}

Thanks.

This works for me:

    "{{ enviro.results[0]['stdout'] }}"

Regards
       Racke