Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

writing ansible facts to a file from a playbook

Tags:

ansible

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?

like image 911
user1309220 Avatar asked Sep 19 '25 03:09

user1309220


1 Answers

- 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

like image 170
saurabh14292 Avatar answered Sep 23 '25 06:09

saurabh14292