# facts to txt file

**URL:** <https://forum.ansible.com/t/facts-to-txt-file/34866>\
**Category:** Ansible Project\
**Created:** [March 26, 2021, 3:31pm UTC](https://forum.ansible.com/t/facts-to-txt-file/34866 "2021-03-26T15:31:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcio\_Xavier](https://avatars.discourse-cdn.com/v4/letter/m/7cd45c/32.png) [@Marcio\_Xavier](https://forum.ansible.com/u/Marcio_Xavier)\
**Post date:** [March 26, 2021, 3:31pm UTC](https://forum.ansible.com/t/facts-to-txt-file/34866/1 "2021-03-26T15:31:48Z")

</div>

Hi all

Is there a way to store facts like (mem,CPU,HD etc ) to a txt file ?

Thanks !  
Marcio X

---

<div class="post-metadata">

**Author:** ![Somasundaram\_R](https://avatars.discourse-cdn.com/v4/letter/s/c2a13f/32.png) [@Somasundaram\_R](https://forum.ansible.com/u/Somasundaram_R)\
**Post date:** [March 26, 2021, 3:38pm UTC](https://forum.ansible.com/t/facts-to-txt-file/34866/2 "2021-03-26T15:38:44Z")

</div>

use ansible-cmdb.  
[https://ansible-cmdb.readthedocs.io/en/latest/#:~:text=Ansible-cmdb%20takes%20the%20output,by%20Ansible%20with%20custom%20data](https://ansible-cmdb.readthedocs.io/en/latest/#:~:text=Ansible%2Dcmdb%20takes%20the%20output,by%20Ansible%20with%20custom%20data).

---

<div class="post-metadata">

**Author:** ![Jorge\_Rua1](https://avatars.discourse-cdn.com/v4/letter/j/a87d85/32.png) [@Jorge\_Rua1](https://forum.ansible.com/u/Jorge_Rua1)\
**Post date:** [March 26, 2021, 3:45pm UTC](https://forum.ansible.com/t/facts-to-txt-file/34866/3 "2021-03-26T15:45:55Z")

</div>

Something like this could do the trick

- name: Dump vars  
hosts: all  
connection: local  
gather\_facts: True  
tasks:
- name: Dump hostvars  
delegate\_to: localhost  
copy:  
content: “{{ hostvars[inventory\_hostname] | to\_nice\_json }}”  
dest: /tmp/setup-{{ inventory\_hostname }}.json  
when:
- debug\_mode | d(True) | bool

If debug\_mode is enabled, it will generate a /tmp/setup-$(hostname).json file with facts gathered in the ansible control machine.

Regards,

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [March 26, 2021, 4:56pm UTC](https://forum.ansible.com/t/facts-to-txt-file/34866/4 "2021-03-26T16:56:53Z")

</div>

fact cache plugins can be used, the JSON one is particularly useful  
for this case.

[https://docs.ansible.com/ansible/latest/plugins/cache.html](https://docs.ansible.com/ansible/latest/plugins/cache.html)

---

<div class="post-metadata">

**Author:** ![Marcio\_Xavier](https://avatars.discourse-cdn.com/v4/letter/m/7cd45c/32.png) [@Marcio\_Xavier](https://forum.ansible.com/u/Marcio_Xavier)\
**Post date:** [March 26, 2021, 6:24pm UTC](https://forum.ansible.com/t/facts-to-txt-file/34866/5 "2021-03-26T18:24:57Z")

</div>

Perfect ! 😇

I am so thankful for you helping guys !  
Have a great weekend

Marcio Xavier
