Facter unable to parse custom fact

1,938 views
Skip to first unread message

Maxim Nikolaev

unread,
Jul 15, 2014, 2:10:59 PM7/15/14
to puppet...@googlegroups.com
Hello

I have strange experience with facter on newly installed servers.

Puppet: 3.6.2
Facter: 2.1.0
OS: Amazon Linux

when I set custom fact to /etc/facter/facts.d and run facter locally I get following error
Fact file /etc/facter/facts.d/services.rb was parsed but returned an empty data set


When I copy same file to
/usr/lib/ruby/site_ruby/1.8/facter/
and run same command - facter works ok.


Can someone advise why thi can happen?

Peter Bukowinski

unread,
Jul 15, 2014, 2:26:57 PM7/15/14
to puppet...@googlegroups.com
When using external facts -- those placed into /etc/facter/facts.d -- on linux, you can use either structured data (yaml, json, or txt), or executable files (shell/ruby/python/perl/etc) to generate facts, but the content/output of these executable files must be in 'key=value'.

If you are unable to run '/etc/facter/facts.d/services.rb' directly from the terminal and have it generate STDOUT in the form of 'factname=factvalue' then you must modify it so that it does. Check that you have a shebang line (like '#!/usr/bin/env ruby') at the top and that the file is executable.

--
Peter Bukowinski

Maxim Nikolaev

unread,
Jul 21, 2014, 11:51:29 AM7/21/14
to puppet...@googlegroups.com
The problem is not fact script. I I run it from /usr/lib/ruby/site_ruby/1.8/facter/ it's working. When I set it to
/etc/facter/facts.d - I get errors. More. If I make link from /etc/facter/facts.d to /usr/lib/ruby/site_ruby/1.8/facter/ also other fact scripts fail.

David Schmitt

unread,
Jul 21, 2014, 2:38:01 PM7/21/14
to puppet...@googlegroups.com
Dear Maxim,

/etc/facter/facts.d and /usr/lib/ruby/site_ruby/1.8/facter/ are used for
two completely different kinds of scripts that cannot be mixed.

/etc/facter/facts.d contains either text files with *static* facts OR
executable *programs* returning a specific text format.

/usr/lib/ruby/site_ruby/1.8/facter/ contains autoloaded ruby code that
is loaded into facter and produces a value internally.

Since these two locations are handled completely differently, linking or
copying from one location to the other cannot work.

Please see the custom fact documentation for more details:

> http://docs.puppetlabs.com/guides/custom_facts.html



Regards, David
> --
> 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
> <mailto:puppet-users...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/14146309-82e9-44f2-bf77-0a277057534e%40googlegroups.com
> <https://groups.google.com/d/msgid/puppet-users/14146309-82e9-44f2-bf77-0a277057534e%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.


--
* Always looking for people I can help with awesome projects *
G+: https://plus.google.com/+DavidSchmitt
Blog: http://club.black.co.at/log/
LinkedIn: http://at.linkedin.com/in/davidschmitt

Maxim Nikolaev

unread,
Jul 22, 2014, 4:33:46 PM7/22/14
to puppet...@googlegroups.com
As I understand from Facrer 2 manual (http://docs.puppetlabs.com/facter/2.1/custom_facts.html#adding-custom-facts-to-facter) I can set all custom facts to  /etc/facts/facts.d.
Fact example:

Facter.add("role") do
  setcode do
    Facter::Util::Resolution.exec('ec2-describe-tags -O KEY -W KEY --filter "resource-id=$(ec2-metadata -i | cut -d " " -f2)" --filter "key=Role" | cut -f5 -')
  end
end

It's not far from examples that are in manual.

When I try to set this fact to /etc/facts/facts.d - I get error: Fact file /etc/facter/facts.d/role.rb was parsed but returned an empty data set
Even if I try to use simple example from manual (
hardware_platform.rb) - I get same error.


On Tuesday, July 15, 2014 5:10:59 PM UTC+3, Maxim Nikolaev wrote:

José Luis Ledesma

unread,
Jul 22, 2014, 4:42:05 PM7/22/14
to puppet...@googlegroups.com

You are confusing custom and external facts, as david explained.

Regards,

--
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/9e76db90-9ea3-4edf-811c-e29442e871b8%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages