Ask Your Question

how to test custom facts?

asked 2014-02-03 14:11:59 -0500

Red Cricket gravatar image

I am attempting to follow the documentation here:


$ sudo puppet agent --configprint factpath

I have created this file on my pe-puppet master:

# cat /var/opt/lib/pe-puppet/facts/red.rb 
# run this to see if you are a red host or no
# wget -O- http://red-www/cgi-bin/puppet-role.cgi?hostname=`hostname`
Facter.add(:role) do
  confine :kernel => "Linux"
  setcode do
    Facter::Util::Resolution.exec('wget -O- http://red-www/cgi-bin/puppet-role.cgi?hostname=`hostname`')

But when I run facter I ... (more)

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2014-02-04 05:49:19 -0500

ffrank gravatar image

To make facter behave like puppet during code lookup, use

facter --puppet
edit flag offensive delete link more


Simple and elegant, I didn't know this one. Why this isn't default behavior?

deric gravatar imagederic ( 2014-02-04 06:57:00 -0500 )edit

Heh, I'm not sure. I guess the idea was to keep the coupling of facter to puppet loose. I suppose facter could detect then the behavior may be appropriate ...(more)

ffrank gravatar imageffrank ( 2014-02-04 08:09:15 -0500 )edit

Thanks! But that only seems to work on my master. On my agent I do not see that fact in the "facter --puppet" output.

Red Cricket gravatar imageRed Cricket ( 2014-02-04 09:29:35 -0500 )edit

Ah, it might be that facter does not use the PE configuration correctly. So you either have to point facter to the puppet.conf to use, or just stick with ...(more)

ffrank gravatar imageffrank ( 2014-02-04 09:46:55 -0500 )edit

answered 2014-02-04 04:20:25 -0500

deric gravatar image

Command line facter is has different load path than in puppet run.

Try this:

   $ FACTERLIB={path to your fact} facter | grep role

in your case:

   $ FACTERLIB=/var/opt/lib/pe-puppet/facts facter | grep role

When you run puppet agent -t you should see that your fact file was loaded, e.g.:

Info: Loading facts in /var/lib/puppet/lib/facter/puppet_vardir.rb
edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

1 follower


Asked: 2014-02-03 14:11:59 -0500

Seen: 2,204 times

Last updated: Feb 04 '14