# Export debug msg to a file

**URL:** <https://forum.ansible.com/t/export-debug-msg-to-a-file/29696>\
**Category:** Ansible Project\
**Created:** [February 18, 2019, 8:58am UTC](https://forum.ansible.com/t/export-debug-msg-to-a-file/29696 "2019-02-18T08:58:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adelmo\_Silva](https://avatars.discourse-cdn.com/v4/letter/a/90db22/32.png) [@Adelmo\_Silva](https://forum.ansible.com/u/Adelmo_Silva)\
**Post date:** [February 18, 2019, 8:58am UTC](https://forum.ansible.com/t/export-debug-msg-to-a-file/29696/1 "2019-02-18T08:58:11Z")

</div>

Good Morning  
I need to send to a text file a message that appears in debug msg after a check if a directory exists. Follow Playbook below. But it is giving error in the recording of the file.

This is my Playbook

hosts: teste  
become: yes  
become\_user: root  
become\_method: sudo  
gather\_facts: yes

tasks:

- name: Verificando Diretórios  
stat:  
path: /etc/teste\_path/  
register: path
- debug:  
msg: “Diretório Ok”  
when: path.stat.isdir is defined and path.stat.isdir
- debug:  
msg: “Diretório Não existe”  
when: path.stat.exists == False
- debug: var=path.stdout\_lines
- name: Gravando Valores  
local\_action: lineinfile path=/root/find\_path.txt line={{path.stdout\_lines}}; create=yes

And results with errors:

ASK [Gravando Valores] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [10.0.10.117]: FAILED! =\> {“msg”: “The task includes an option with an undefined variable. The error was: ‘dict object’ has no attribute ‘stdout\_lines’\n\nThe error appears to have been in ‘/root/Ansible/Playbooks/find\_path.yaml’: line 24, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Gravando Valores\n ^ here\n\nexception type: \<class ‘ansible.errors.AnsibleUndefinedVariable’\>\nexception: ‘dict object’ has no attribute ‘stdout\_lines’”}  
fatal: [10.0.10.122]: FAILED! =\> {“msg”: “The task includes an option with an undefined variable. The error was: ‘dict object’ has no attribute ‘stdout\_lines’\n\nThe error appears to have been in ‘/root/Ansible/Playbooks/find\_path.yaml’: line 24, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Gravando Valores\n ^ here\n\nexception type: \<class ‘ansible.errors.AnsibleUndefinedVariable’\>\nexception: ‘dict object’ has no attribute ‘stdout\_lines’”}  
to retry, use: --limit @/root/Ansible/Playbooks/find\_path.retry

Thansk for your attention.

---

<div class="post-metadata">

**Author:** ![Mike\_Klebolt](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mike\_Klebolt](https://forum.ansible.com/u/Mike_Klebolt)\
**Post date:** [February 18, 2019, 6:56pm UTC](https://forum.ansible.com/t/export-debug-msg-to-a-file/29696/2 "2019-02-18T18:56:03Z")

</div>

The stat module does not have a return key of stdout\_lines. For a list of data that is returned from the stat module please reference this page [here](https://docs.ansible.com/ansible/latest/modules/stat_module.html#return-values).
