custom facts

37 views
Skip to first unread message

Michael Di Domenico

unread,
Apr 25, 2018, 10:01:00 AM4/25/18
to puppet...@googlegroups.com
i'm upgrading from puppet 3 (via epel) to puppet 5 (via puppetlabs),
i'm confused on how/if there's a way to get custom ruby facts to load
into facter without having to specify FACTERLIB. i'll admit i might
have missed something in the documentation

in the past i'd copy my ruby facts into
/usr/share/ruby/vendor_ruby_facter (which probably wasnt right), and
everytime I ran facter it would autoload my facts, no need for
switches to env variables

there is a /opt/puppetlabs/puppet/lib/ruby/vendor_ruby, but when i
copy my facts into there they don't load

what's the right way to do this?

Luke Bigum

unread,
Apr 25, 2018, 10:14:08 AM4/25/18
to Puppet Users
On Wednesday, 25 April 2018 15:01:00 UTC+1, Michael Di Domenico wrote:
in the past i'd copy my ruby facts into
/usr/share/ruby/vendor_ruby_facter (which probably wasnt right)

No... That's definitely not right :-)  Puppet has had a feature called "pluginsync" for a while now, which downloads ruby code (types, providers, facts) from a Puppet Master before it does anything on a Puppet Agent.  The Agent will write it's downloaded Ruby code into /var/lib/puppet/lib/ (/opt/puppetlabs/puppet/cache/lib in Puppet 5), and it will keep it synchronised so you can't pollute it.

Probably the simplest thing for you to do right now is create a new module (call it yourcompany_stdlib ?) and put all your Facts in there.  Custom Facts distributed from a module live in MODULEROOT/lib/facter/, here some examples from Puppetlabs' stdlib. You just put your .rb files in this directory:


Then if you add that module to your Puppet Master, your Agents will magically synchronise them down - Puppet 3 and Puppet 5 (you don't need to "include" or do anything in a manifest).

I'd link you some puppet.com Docs too, but right now I'm getting 5xx Cloud Flare errors.  If it's working for you, look around for how to distribute custom facts in a module.

Michael Di Domenico

unread,
Apr 25, 2018, 10:18:13 AM4/25/18
to puppet...@googlegroups.com
On Wed, Apr 25, 2018 at 10:14 AM, Luke Bigum <Luke....@lmax.com> wrote:
> On Wednesday, 25 April 2018 15:01:00 UTC+1, Michael Di Domenico wrote:
>>
>> in the past i'd copy my ruby facts into
>> /usr/share/ruby/vendor_ruby_facter (which probably wasnt right)
>
>
> No... That's definitely not right :-) Puppet has had a feature called
> "pluginsync" for a while now, which downloads ruby code (types, providers,
> facts) from a Puppet Master before it does anything on a Puppet Agent. The
> Agent will write it's downloaded Ruby code into /var/lib/puppet/lib/
> (/opt/puppetlabs/puppet/cache/lib in Puppet 5), and it will keep it
> synchronised so you can't pollute it.

we're using puppet in standalone mode, not server/client.

Luke Bigum

unread,
Apr 25, 2018, 11:52:37 AM4/25/18
to Puppet Users
Perhaps something like this then, though that answer is old, in theory it should probably work for new Puppet:

R.I.Pienaar

unread,
Apr 25, 2018, 11:58:10 AM4/25/18
to puppet...@googlegroups.com
In recent Puppet with puppet apply it automatically finds facts in your modules, you dont need to copy them anywhere or sync them.

I have not really been following this thread sorry if that's not helpful - but it basically just works

--
R.I.Pienaar / www.devco.net / @ripienaar

Luke Bigum

unread,
Apr 25, 2018, 12:46:48 PM4/25/18
to Puppet Users
I think the RP is trying to run Facter standalone on the command line, as he mentions FACTERLIB, but yes, "puppet apply" should just work as is.

Michael Di Domenico

unread,
Apr 25, 2018, 1:05:18 PM4/25/18
to puppet...@googlegroups.com
>> >
>> > Perhaps something like this then, though that answer is old, in theory
>> > it
>> > should probably work for new Puppet:
>> >
>> > https://ask.puppet.com/question/4645/puppet-apply-and-pluginsync/
>> >
>>
>> In recent Puppet with puppet apply it automatically finds facts in your
>> modules, you dont need to copy them anywhere or sync them.
>>
>> I have not really been following this thread sorry if that's not helpful -
>> but it basically just works
>
> I think the RP is trying to run Facter standalone on the command line, as he
> mentions FACTERLIB, but yes, "puppet apply" should just work as is.

yes, that is true. i want both facter and puppet to be able to find
my custom facts without having to specify an environment variable.

thanks for suggestions so far, i'll poke at them and see if something
fits the bill

R.I.Pienaar

unread,
Apr 25, 2018, 1:26:40 PM4/25/18
to puppet...@googlegroups.com
Facter on it's own can't I believe, you have to use puppet facts then you will get facts from modules - but beware the slightly different format.

Michael Di Domenico

unread,
Apr 25, 2018, 3:16:30 PM4/25/18
to puppet...@googlegroups.com
so i finally figured out a method, though i'm not gonna lie it's pretty hacky

based on this page https://puppet.com/docs/facter/3.7/custom_facts.html

Using the Ruby load path

Facter searches all directories in the Ruby $LOAD_PATH variable for
subdirectories named facter, and loads all Ruby files in those
directories. If you had a directory in your $LOAD_PATH like
~/lib/ruby, set up like this:

#~/lib/ruby
└── facter
├── rackspace.rb
├── system_load.rb
└── users.rb

so if you then

/opt/puppetlabs/puppet/bin/ruby -e 'puts $LOAD_PATH'

you'll get a list if directories that facter should search in for a
directory called 'facter'

i created /opt/puppetlabs/puppet/lib/ruby/site_ruby/facter and dumped
my custom ruby facts into there

running facter or facter -p now picks up those facts and includes them
by default

i'm sure this isn't the best method, but it works for now
> --
> You received this message because you are subscribed to the Google Groups "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/1524677188.3836288.1350590520.7354DA1B%40webmail.messagingengine.com.
> For more options, visit https://groups.google.com/d/optout.

Thomas Müller

unread,
Apr 26, 2018, 8:38:32 AM4/26/18
to Puppet Users

what are your "custom facts" ? Custom facts in modules get automatically synced to the puppet agent or for puppet apply.

If you manage your facts yourself and not by modules you might configure the custom-dir within the facter.conf https://puppet.com/docs/facter/3.11/configuring_facter.html

- Thomas

 

jcbollinger

unread,
Apr 26, 2018, 8:58:11 AM4/26/18
to Puppet Users


On Wednesday, April 25, 2018 at 12:05:18 PM UTC-5, Michael Di Domenico wrote:
 
yes, that is true.  i want both facter and puppet to be able to find
my custom facts without having to specify an environment variable. 

But you're chasing the wrong objective.  You should not be using facter (directly) to evaluate custom facts provided by Puppet, at least with puppet5.  Instead, use puppet's 'facts' face:

$ puppet facts

That should, again, Just Work, regardless of whether you normally use 'puppet apply' or obtain catalogs from a master.


John

 

Michael Di Domenico

unread,
Apr 26, 2018, 10:13:44 AM4/26/18
to puppet...@googlegroups.com
yes, that's likely true. i'm still learning and i didn't build the
original environment, so change is hard and has to be slow, small
steps
Reply all
Reply to author
Forward
0 new messages