Ask Your Question

What is a good way of retrieving/caching external facts from a database using facter?

asked 2016-08-09 19:58:56 -0500

wfsaxton gravatar image

updated 2016-08-10 01:48:47 -0500

We currently store all of our systems in a database table, along with some user-defined attributes, such as the system's location. I would like to use these variables in our Hiera hiearchy so that we can use, for example, location specific variables within the hierarchy.

- "/node/%{::nodename}"
- "/location/%{::location}"
- "common"

So, it appears I need to retrieve these variables from the database and put them into facter somehow. I'm just not quite sure what the "best" way to do this would be.

If I use custom facts, I could run a CLI command to query the database, get the values, and put them into facter variables. Would this be a good approach? Is there some other "best practice" I should use?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-08-10 01:11:05 -0500

kaizenCoder gravatar image

updated 2016-08-10 02:32:39 -0500

This is perhaps a comment but it was too long to be one.

I don't fully understand your requirements however have you looked at writing custom facts? I believe this is different to external factswhere you write the custom fact inside your module and it is executed on each agent run. See

The benefit of this approach is it becomes accessible within your module .

You can add new facts by writing snippets of Ruby code on the Puppet master. Puppet then uses Plugins in Modules to distribute the facts to the client.

As part of the agent run, it will retrieve the fact(s) and send it to the master. The master will compile the catalogue along with the default facts and send it back to the agent to be applied.

Update 1:

Based on your re-write of the question, it appears that an external fact would suffice. It would be a script that retrieves the location and stores it in a facter variable. You can also deploy the script via Puppet to all nodes (assuming it it is environment agnostic).

edit flag offensive delete link more


Sorry for the confusion, I re-wrote my question to hopefully make it more clear. I certainly want my custom variables to be accessible in different places (running facter manually, in the Hiera hierarchy, in an ENC, etc)

wfsaxton gravatar imagewfsaxton ( 2016-08-10 01:50:40 -0500 )edit

Based on your re-write, I think an external fact is a better choice. As far as 'best practices' go I don't believe there is one, because that would assume it satisfies 'every' requirement/criteria.

kaizenCoder gravatar imagekaizenCoder ( 2016-08-10 02:29:07 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2016-08-09 19:58:56 -0500

Seen: 105 times

Last updated: Aug 10 '16