custom fact in custom facts resolves to nil

229 views
Skip to first unread message

ashe...@gmail.com

unread,
May 27, 2015, 2:36:39 AM5/27/15
to puppet...@googlegroups.com
Hi,

is it possible to use custom facts inside other custom facts?

With facter -p the custom fact is listed ( e.g.):

...
userblweb => 1000

With irb:

irb(main):001:0> require 'facter'
=> true
irb(main):002:0> a = Facter.value(:userblweb)
=> nil

Any idea?

puppetversion: 3.7.3
facter 2.3.0

Regards
Andreas

Thomas Müller

unread,
May 27, 2015, 5:26:35 AM5/27/15
to puppet...@googlegroups.com


Am Mittwoch, 27. Mai 2015 08:36:39 UTC+2 schrieb ashe...@gmail.com:
Hi,

is it possible to use custom facts inside other custom facts?

With facter -p the custom fact is listed ( e.g.):

 the -p / --puppet flag for facter is deprecated. use of "puppet facts" will be required. 

 
...
userblweb => 1000

With irb:

irb(main):001:0> require 'facter'
=> true
irb(main):002:0> a = Facter.value(:userblweb)
=> nil

Any idea?

You would need to  somehow do what the -p/--puppet flag does so it loads the facts in the puppet environment.

another note: IMHO ruby facter is also deprecated and native facter will be default with facter v3.

- Thomas

Thomas Müller

unread,
May 27, 2015, 8:24:58 AM5/27/15
to puppet...@googlegroups.com


Am Mittwoch, 27. Mai 2015 11:26:35 UTC+2 schrieb Thomas Müller:


Am Mittwoch, 27. Mai 2015 08:36:39 UTC+2 schrieb ashe...@gmail.com:
Hi,

is it possible to use custom facts inside other custom facts?

With facter -p the custom fact is listed ( e.g.):

 the -p / --puppet flag for facter is deprecated. use of "puppet facts" will be required. 

 
...
userblweb => 1000

With irb:

irb(main):001:0> require 'facter'
=> true
irb(main):002:0> a = Facter.value(:userblweb)
=> nil

Any idea?

You would need to  somehow do what the -p/--puppet flag does so it loads the facts in the puppet environment.

Peter Huene

unread,
May 27, 2015, 12:50:56 PM5/27/15
to puppet...@googlegroups.com
Hi Andreas,

On Tue, May 26, 2015 at 11:16 PM, <ashe...@gmail.com> wrote:
Hi,

is it possible to use custom facts inside other custom facts?

With facter -p the custom fact is listed ( e.g.):

...
userblweb => 1000

With irb:

irb(main):001:0> require 'facter'
=> true
irb(main):002:0> a = Facter.value(:userblweb)
=> nil

Any idea?

When using the Facter API, Facter needs to be told where the custom facts are stored:

irb> Facter.search '<path_to_custom_facts>'

Note: despite being a verb, the 'search' method only adds the given path to the list of search paths.

The same thing happens during Puppet's settings initialization that is invoked when you pass the '-p' option to Facter (as Thomas mentioned, this is deprecated).

Likewise, the path can be specified to Facter by using the FACTERLIB environment variable set to a list of paths to search for custom facts.

Facter 3 will be adding a '--custom-dir' command line option that is another way of specifying where custom facts are stored.

I hope this helps.


--
Join us at PuppetConf 2015, October 5-9 in Portland, OR - www.2015.puppetconf.com 
Register early to save 40%!

ashe...@gmail.com

unread,
May 29, 2015, 3:09:55 AM5/29/15
to puppet...@googlegroups.com
Hi Peter, hi Thmaos,

I'll need some time to test your suggestions.

- Andreas

ashe...@gmail.com

unread,
May 29, 2015, 3:46:37 AM5/29/15
to puppet...@googlegroups.com
Hi,

one question. I'm using pluginsync.

"Custom facts can be distributed to clients using the Plugins in Modules method."

That seems not to be enough.

So what is the path I've to use? Is it the path to the *rb files e.g. ../<modulename>/lib/facter?

-Andreas

David Schmitt

unread,
May 31, 2015, 10:25:14 AM5/31/15
to puppet...@googlegroups.com
On 2015-05-29 08:46, ashe...@gmail.com wrote:
> Hi,
>
> one question. I'm using pluginsync.
>
> "Custom facts can be distributed to clients using the Plugins in Modules
> <https://docs.puppetlabs.com/guides/plugins_in_modules.html> method."
>
> That seems not to be enough.
>
> So what is the path I've to use? Is it the path to the *rb files e.g.
> ../<modulename>/lib/facter?


Yes, and enabling --pluginsync on the agent.


Regards, David

ashe...@gmail.com

unread,
Jun 1, 2015, 3:30:37 AM6/1/15
to puppet...@googlegroups.com
Hi all,

first thanks to all of you. At least I found a solution taking a bit from all the hints. This is ( one possible ) solution:


irb(main):001:0> require 'facter'
=> true
irb(main):002:0> require 'puppet'
=> true
irb(main):003:0> a = Facter.value(:userblweb)
=> nil
irb(main):004:0> Puppet.initialize_settings
=> "notice"
irb(main):005:0> a = Facter.value(:userblweb)
=> "1000\n"

As you can see, after invoking initialize_settings my custom fact seems to be in place / known to facter. Now I'll have a look how it works outside irb in real puppet master/agent environment.

Regards
Andreas

Am Mittwoch, 27. Mai 2015 08:36:39 UTC+2 schrieb ashe...@gmail.com:

ashe...@gmail.com

unread,
Jun 3, 2015, 8:04:12 AM6/3/15
to puppet...@googlegroups.com
Hi all,

I tested ib master / agent environment and the problem isn't there anymore?! I don't know what went wrong for the first time. But now every works as expected.

Regards
Andreas
Reply all
Reply to author
Forward
0 new messages