cancel
Showing results for 
Search instead for 
Did you mean: 
Robert_Bryant
Flight Engineer
Flight Engineer
  • 2,309 Views

Ansible custom fact files location

Jump to solution

I am pulling my hair to the point of almost bald with finding an answer to this... very... simple... question.

  1. I know managed hosts can return custom facts defined in /etc/ansible/facts.d/*.fact.
  2. I know to gather those custom facts from managed hosts during a playbook, you have to copy that .fact file there first, completely clear on how to do that.
  3. In the example below, the variable facts_file: custom.fact is a relative path, or at least appears not to be an absolute path:

RH294 Guided exercise 'Managing Facts' Ch.3, p.121:

---
- name: Install remote facts
  hosts: webserver
  vars:
    remote_dir: /etc/ansible/facts.d
    facts_file: custom.fact

...output omitted...

(We're in /home/student/data-facts/ )

I know that in whatever directory we're working with Ansible in (ansible.cfg and inventory present), that the relative path sub-directories group_vars and host_vars are automatically parsed for files if the playbook file being run is at the same level.

What's driving me absolutely berserk is that there is zero discussion in the text of where you can or should stage the .fact files on the Ansible controller host, that you want to send to the managed hosts before you run the setup module to gather their sum facts. Nor does the GE say anything about the path. The problem for me is, the GE has you create that file as /home/student/data-facts/custom.fact. The directory /home/student/data-facts/ has the playbook and the ansible.cfg and the inventory in it, so that's the directory where we're working, and it governs all the host and group variable directory parsing, Ansible config precedence, yada yada yada.

The $64,000 question: Is it OK to use a sub-directory and call multiple custom facts files?

i.e. can we do this? :

---
- name: Install remote facts
  hosts: webserver
  vars:
    remote_dir: /etc/ansible/facts.d
    facts_file: /home/student/custom_facts/custom-net.fact
    facts_file: /home/student/custom_facts/custom-disk.fact

...output omitted...

 

Labels (1)
1 Solution

Accepted Solutions
Robert_Bryant
Flight Engineer
Flight Engineer
  • 2,285 Views

So, YES, this works. And it's probably a very good idea to organize and manage fact files. Give them meaningful arbitrary names that you can easily recognize for ease of use. Facts can be for specific managed hosts, types of managed hosts, OS versions, disk configurations, sets of files, certain software packages or modules, systemctl units, whatever. Very specific tweaks for very specific purposes. better than cluttering your Ansible working directory on the host controller with lots of loose files of varying types.

I have to say, as good as Red Hat self-paced video learning is, the ability to raise your hand and ask a question is sorely missed. You almost always learn more than you expected seeking the answer, but sometimes it'd be nice to have a question answered in real time and stay on pace with the course.

View solution in original post

1 Reply
Robert_Bryant
Flight Engineer
Flight Engineer
  • 2,286 Views

So, YES, this works. And it's probably a very good idea to organize and manage fact files. Give them meaningful arbitrary names that you can easily recognize for ease of use. Facts can be for specific managed hosts, types of managed hosts, OS versions, disk configurations, sets of files, certain software packages or modules, systemctl units, whatever. Very specific tweaks for very specific purposes. better than cluttering your Ansible working directory on the host controller with lots of loose files of varying types.

I have to say, as good as Red Hat self-paced video learning is, the ability to raise your hand and ask a question is sorely missed. You almost always learn more than you expected seeking the answer, but sometimes it'd be nice to have a question answered in real time and stay on pace with the course.

Join the discussion
You must log in to join this conversation.