source: other-projects/hathitrust/vagrant-solr-cluster/trunk/modules/stdlib/README_DEVELOPER.markdown@ 30989

Last change on this file since 30989 was 30960, checked in by davidb, 7 years ago

Switch to using Puppet to provision machine. Strongly based on files developed for spark-hdfs cluster

File size: 1.3 KB
Line 
1Puppet Specific Facts
2=====================
3
4Facter is meant to stand alone and apart from Puppet. However, Facter often
5runs inside Puppet and all custom facts included in the stdlib module will
6almost always be evaluated in the context of Puppet and Facter working
7together.
8
9Still, we don't want to write custom facts that blow up in the users face if
10Puppet is not loaded in memory. This is often the case if the user runs
11`facter` without also supplying the `--puppet` flag.
12
13Ah! But Jeff, the custom fact won't be in the `$LOAD_PATH` unless the user
14supplies `--facter`! You might say...
15
16Not (always) true I say! If the user happens to have a CWD of
17`<modulepath>/stdlib/lib` then the facts will automatically be evaluated and
18blow up.
19
20In any event, it's pretty easy to write a fact that has no value if Puppet is
21not loaded. Simply do it like this:
22
23 Facter.add(:node_vardir) do
24 setcode do
25 # This will be nil if Puppet is not available.
26 Facter::Util::PuppetSettings.with_puppet do
27 Puppet[:vardir]
28 end
29 end
30 end
31
32The `Facter::Util::PuppetSettings.with_puppet` method accepts a block and
33yields to it only if the Puppet library is loaded. If the Puppet library is
34not loaded, then the method silently returns `nil` which Facter interprets as
35an undefined fact value. The net effect is that the fact won't be set.
Note: See TracBrowser for help on using the repository browser.