Ask Your Question

Custom Facts are always empty

asked 2018-03-08 16:51:13 -0600

orestes910 gravatar image


puppetserver 2.7.2 puppet 3.6.2 facter 2.4.1

These versions seem wonky, but they're the latest using Foreman/CentOS 7.

Either way, it seems no matter what, my custom facts are empty. I've tried ruby facts:

Facter.add('location') do
  setcode do
     Facter::Core::Execution.execute('/usr/bin/hostname | /bin/cut -d. -f2')

I've tried external facts returning location=value

Nothing I try returns anything from facter, the values are always just empty. If I put a file with location=value in it that seems to work, but I'd rather not have to deal with a job to execute this and would instead prefer to just generate it on puppet run. Running facter -p location on the client returns empty and adding the -d flag outputs nothing useful. Can someone point me in the right direction?

edit retag flag offensive close merge delete


Why, what, why aren't using the core facts? The core fact `$facts['networking']['fqdn']` in particular. You can explode it by doing `split($facts['networking']['fqdn'], '\.')`. By the way, your fact is always empty, because you're wrongly invoking hostname(1). You must specify the `-f` flag.

Kai Burghardt gravatar imageKai Burghardt ( 2018-03-11 09:40:07 -0600 )edit

with older puppet, I had to run `sudo facter -p` to actually see my custom facts, or manually set the FACTERLIB inline with the command like this. `FACTERLIB=/var/lib/puppet/lib/facter:/var/lib/puppet/facts facter -p`. I would also do the same thing to irb to develop custom facts

DarylW gravatar imageDarylW ( 2018-03-14 09:12:36 -0600 )edit

Kai, I ended up doing as you say and using existing facts. The hostname command returns fine without -f on my system though.

orestes910 gravatar imageorestes910 ( 2018-03-14 09:58:26 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2018-03-14 09:15:32 -0600

DarylW gravatar image

I guess I'll move my above comment into an actual answer..

With puppet3, for some reason I would only see custom facts when running sudo facter -p and not just facter -p, probably for the same reason that your ssldir and other configuration is different if you run it as root vs non-root user. I was able to run as non-root but explicitly setting the FACTERLIB like so...

FACTERLIB=/var/lib/puppet/lib/facter:/var/lib/puppet/facts facter -p

I would also do the same thing to copy/paste my custom facts into irb to work on developing/debugging them directly..

FACTERLIB=/var/lib/puppet/lib/facter:/var/lib/puppet/facts irb
edit flag offensive delete link more


The odd bit is that the facts return just fine with facter -p, but puppet doesn't pick them up when run. I've ended up just using built in facts as much as possible and manipulating those. I think this might just be a bug in my combination of versions.

orestes910 gravatar imageorestes910 ( 2018-03-14 09:59:53 -0600 )edit

is there a permissions issue on your files? Is puppet running as the puppet user? Can that user read/execute those files?

DarylW gravatar imageDarylW ( 2018-03-16 08:29:06 -0600 )edit

answered 2018-03-14 03:17:12 -0600

natemccurdy gravatar image

From the command line, if you want to view custom (ruby) facts, you need to add -p to Facter.

Like this:

facter -p location

-p will load the Puppet libraries hence the letter p.

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: 2018-03-08 16:51:13 -0600

Seen: 244 times

Last updated: Mar 14