Custom facts not working

2,373 views
Skip to first unread message

Jonathan Gazeley

unread,
Oct 3, 2011, 6:00:18 AM10/3/11
to puppet...@googlegroups.com
Hi all,

I'm experiencing some difficulty getting custom facts to run. I've
installed them on the puppetmaster in:

${modulepath}/${module}/lib/facter/*.rb

and from there they appear to be copied properly onto the clients, where
they end up in:

/var/lib/puppet/lib/facter/*.rb

On all clients, in puppet.log, the output of puppet-agent mentions
"Loading facts" and seems to do the right thing. However, running facter
on the client, the facts do not show up, even with --debug and with sudo.

On the puppetmaster, they do show up in facter output as expected.

So what's going wrong? I'm running CentOS 6 and Puppet 2.6.6.

Thanks,
Jonathan

Stefan Schulte

unread,
Oct 3, 2011, 6:14:30 AM10/3/11
to puppet...@googlegroups.com

I guess facter as a standalone executable doesn't look into
/var/lib/puppet. Try running

FACTERLIB=/var/lib/puppet/lib/facter facter

as described in the custom facts guide [1]

[1] http://docs.puppetlabs.com/guides/custom_facts.html#an-example

-Stefan

Jonathan Gazeley

unread,
Oct 3, 2011, 7:08:23 AM10/3/11
to puppet...@googlegroups.com

Thank you. This fix enables me to view the facts on the command line.
Will any further action be necessary to use the facts in Puppet?

Jonathan

Stefan Schulte

unread,
Oct 3, 2011, 7:54:37 AM10/3/11
to puppet...@googlegroups.com

no, you should be able to refer to a custom fact immediatly if your
agent is configured to do pluginsync (which you apparently did enable
already).

-Stefan

Todd Zullinger

unread,
Oct 3, 2011, 9:24:56 AM10/3/11
to puppet...@googlegroups.com
Stefan Schulte wrote:
> I guess facter as a standalone executable doesn't look into
> /var/lib/puppet. Try running
>
> FACTERLIB=/var/lib/puppet/lib/facter facter
>
> as described in the custom facts guide [1]
>
> [1] http://docs.puppetlabs.com/guides/custom_facts.html#an-example

Or use the -p | --puppet option to facter.

--
Todd OpenPGP -> KeyID: 0xBEAF0CE3 | URL: www.pobox.com/~tmz/pgp
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When buying and selling are controlled by legislation, the first
things to be bought and sold are legislators.
-- P.J. O'Rourke

Jonathan Gazeley

unread,
Oct 3, 2011, 9:37:29 AM10/3/11
to puppet...@googlegroups.com
On 03/10/11 14:24, Todd Zullinger wrote:
> Stefan Schulte wrote:
>> I guess facter as a standalone executable doesn't look into
>> /var/lib/puppet. Try running
>>
>> FACTERLIB=/var/lib/puppet/lib/facter facter
>>
>> as described in the custom facts guide [1]
>>
>> [1] http://docs.puppetlabs.com/guides/custom_facts.html#an-example
>
> Or use the -p | --puppet option to facter.
>

I tried the -p option, and it didn't seem to have any effect. But
setting the FACTERLIB variable as Stefan suggested has worked.

Thanks,
Jonathan

jcbollinger

unread,
Apr 3, 2013, 10:23:41 AM4/3/13
to puppet...@googlegroups.com


On Wednesday, April 3, 2013 2:44:22 AM UTC-5, Codfather wrote:
Worth noting that if you set this environment variable in one of your shell environment config files , like .bashrc, you would need to export it.

Like this 

export FACTERLIB=/var/lib/puppet/lib/facter


True, but it's even more worth noting that you should not assume that shell configuration files will be involved in any way in setting up the environment in which Facter or Puppet runs, unless you launch them manually from an interactive shell.  Even then, you will find that Puppet is parsimonious about the environment it provides to child processes, so putting a variable in the agent's environment does not necessarily imply that Facter will see it when run by the agent.


John

Codfather

unread,
Apr 4, 2013, 6:12:21 AM4/4/13
to puppet...@googlegroups.com
Good point John, though you must remember a lot of users utilise cron to drive the puppet run's on standalone and agents. 

So this environment variable is important , especially for cloud based deployments that don't use a puppet master.

Certainly with Ubuntu servers in standalone mode, I have found that unless this is set, the custom facts are not loaded properly.

Cheers

Nick

jcbollinger

unread,
Apr 4, 2013, 11:30:39 AM4/4/13
to puppet...@googlegroups.com


On Thursday, April 4, 2013 5:12:21 AM UTC-5, Codfather wrote:
Good point John, though you must remember a lot of users utilise cron to drive the puppet run's on standalone and agents. 


I'm well aware of that.
 

So this environment variable is important , especially for cloud based deployments that don't use a puppet master.


The variable is important, but for most cron implementations, .bashrc is not.  Most crons take care to provide an exceedingly sparse environment to the commands they spawn, much as Puppet does.  If you want your cron jobs to have that environment variable set then you should use their crontab entries to make it so, not .bashrc.  If you have a cron that doesn't require you to do so then you should find a more secure implementation.


John

Reply all
Reply to author
Forward
0 new messages