facter: setting up module-specific custom facts?

2

1

I am customizing an existing puppet installation (with facter) and I think I ran into an issue understanding the scope of custom facts.

I have several modules that are mapped exclusively to different classes of hosts within a nodes.pp file. What I'd like to achieve would be to have custom facts limited by module, for example hosts in module1 would execute custom_fact_1 and hosts in module2 would only execute custom_fact_2.

According to the facter/puppet docs, the custom facts go into a <module-name>/lib/facter directory, and are tied to that module.

I have made it gather a few custom facts already, by adding the ruby scripts to a single module's lib/facter dir, but strangely they are not limiting themselves to the hosts to which the module is assigned. What is happening is that all custom facts are ran for all hosts (even the ones that don't have any relationship to that module), which is not exactly what I intended.

Did I misunderstand the documentation? Is this type of fact-module mapping possible?

Note: I have achieved a similar behaviour by using confine instructions in the custom facts scripts, but this goes against the intended purpose, since I'd like to tie the custom facts to the modules themselves and not have the mapping in the scripts.

André Fernandes

Posted 2012-07-17T09:00:54.230

Reputation: 389

Answers

-1

Facter is unsuited for this. It would be much simpler to custom functions per module or use an ENC such as hiera.

dhchdhd

Posted 2012-07-17T09:00:54.230

Reputation: 198

-1

That's expected behaviour yes, if you've got pluginsync enabled then lib/facter from all modules ends up on all nodes.

Rasputnik

Posted 2012-07-17T09:00:54.230

Reputation: 99

-1

To answer your question as directly as possible, most setups I've seen use groups of some fashion to categorize systems. Often those groups map pretty closely to modules, and you can use those group facts to confine the facts to those systems.

What are you trying to do with these facts? As others mentioned, types or functions may also give you what you need without being available everywhere. More info about what you're doing would be helpful!

liquidki

Posted 2012-07-17T09:00:54.230

Reputation: 101