1

I know I can use the command below to save all ansible facts to a file:

ansible all -m setup --tree facts.d/

But I want to do this within a playbook. Currently I have:

- name: Collect facts
  setup:
    fact_path:  facts.d

But nothing is collected when I run the task. Am I missing something?

user1309220
  • 129
  • 4
  • 15
  • I'm not aware of any playbook mechanism to do that, and in fairness that `--tree` is not "saving ansible facts to a file" but is instead writing the _log messages_ to a file, a subtle but important difference – mdaniel Jun 08 '21 at 16:06

1 Answers1

3
- name: save all facts to host specific file
  copy:
    content: "{{ ansible_delegated_vars[inventory_hostname].vars | to_nice_json }}"
    dest: "{{ playbook_dir }}/{{ ansible_fqdn }}"
  delegate_to: localhost

This will create a file per host at playbook dir.

Reference : https://groups.google.com/g/ansible-project/c/HI65wOUIrx4?pli=1

saurabh14292
  • 1,281
  • 2
  • 10
  • 12