How to get Custom Facts only in Ansible?

Viewed 318

I am using Ansible for configuring the remote nodes. Now, i need to get some information from these nodes to take decisions at ansible master.

So, i tried the Custom Facts.

1. Created facts.d directory in /etc/ansible/
2. Created a file test.facts in facts.d directory.
3. Response of the test.facts is JSON.
4. Execution permission is given for the facts file.

It's working. But, i felt its slow because it gathers default facts as well.

Is there a way to receive the custom facts of test.facts file alone?

1 Answers

You cannot limit to a specific .fact file alone, but you can easilly:

  • filter out anything but the ansible_local facts
  • limit to the subset containing the above facts.

Although I'm not quite sure this will have a very noticeable impact on performance, after some blind tries on my local machine, the following seems to work:

ansible localhost -m setup -a 'gather_subset=!all,!min,virtual' -a filter=ansible_local

Meanwhile, if facts gathering time really becomes an issue, you should consider switching to a persistent facts cache plugin and review your gathering strategy

Related