facts to txt file

32 views
Skip to first unread message

mrcx...@gmail.com

unread,
Mar 26, 2021, 11:31:48 AM3/26/21
to Ansible Project
Hi all

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

Thanks !
Marcio X

Somasundaram R

unread,
Mar 26, 2021, 11:38:44 AM3/26/21
to Ansible Project

Jorge Rúa

unread,
Mar 26, 2021, 11:46:20 AM3/26/21
to ansible...@googlegroups.com
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,







--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/5d14487a-2b9d-44cf-a3c5-bd5b2cf51f11n%40googlegroups.com.

Brian Coca

unread,
Mar 26, 2021, 12:57:22 PM3/26/21
to Ansible Project
fact cache plugins can be used, the JSON one is particularly useful
for this case.

https://docs.ansible.com/ansible/latest/plugins/cache.html



--
----------
Brian Coca

Marcio Xavier

unread,
Mar 26, 2021, 2:25:19 PM3/26/21
to ansible...@googlegroups.com
Perfect ! 😇

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

Marcio Xavier



Reply all
Reply to author
Forward
0 new messages