Facter with a gem

131 views
Skip to first unread message

patant

unread,
May 13, 2011, 10:05:59 AM5/13/11
to puppet...@googlegroups.com
Hi,

Created a facter that require a gem. The gem is installed on all the servers involved.
But when I trigger puppet I get an error in the log:
Could not run Puppet configuration client: Could not retrieve local facts: no such file to load -- <gem name>

Is there a way to make puppet use/find the gem?

Using Puppet 2.6.1

Regard,
Patrik

Patrick

unread,
May 13, 2011, 10:55:13 AM5/13/11
to puppet...@googlegroups.com

Facter is run on the clients. Does installing that gem on the clients fix the error?

Pietro Monteiro

unread,
May 13, 2011, 12:49:08 PM5/13/11
to puppet...@googlegroups.com, Patrick
On 05/13/2011 07:55 AM, Patrick wrote:
> Facter is run on the clients. Does installing that gem on the clients
> fix the error?
>

Also, "require 'rubygems'" on the top of the file where you define your
facter.

--
Pietro Monteiro
Senior Developer
DECK Monitoring
115 W 8th Ave. Eugene, Oregon 97401
Office: 541-343-0110
www.deckmonitoring.com

patant

unread,
May 14, 2011, 12:08:28 PM5/14/11
to puppet...@googlegroups.com
The gem is installed on the clients and the facter works on the client. It's when I do the puppet apply/run I get the error.

patant

unread,
May 14, 2011, 12:09:26 PM5/14/11
to puppet...@googlegroups.com, Patrick
I do require rubygems.

Matt Robinson

unread,
May 17, 2011, 12:52:30 PM5/17/11
to puppet...@googlegroups.com, Patrick
require 'rubygems'
require 'yourgemname'

That should be enough. You're going to have to start giving more info
you want more help. At the very least the gem name. Sometimes you
think you're requiring the gem correctly based on the gem name, but
the thing you need to require might not match the gem name exactly.
For example, there's an rspec-core gem, but you don't do "require
'rspec-core'", you do "require 'rspec/core'".

This really shouldn't be a facter issue, it's a ruby issue. Try just
putting the requires in an empty file and using ruby to run that. If
it works there and doesn't in the facter code, paste your code into a
gist so that people can see the whole thing.
Matt

> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To post to this group, send email to puppet...@googlegroups.com.
> To unsubscribe from this group, send email to
> puppet-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/puppet-users?hl=en.
>
>

patant

unread,
May 17, 2011, 3:01:50 PM5/17/11
to puppet...@googlegroups.com, Patrick
Found the error:
require 'rubygems'
require 'mygem'
Facter.add("myfacter") do
 setcode do
------ 

This works:
Facter.add("myfacter") do
require 'rubygems'
require 'mygem'
 setcode do
-------

Michael Knox

unread,
May 17, 2011, 6:17:13 PM5/17/11
to puppet...@googlegroups.com
I extend this a bit in some of my facts to check that the gem is available before using it. That way if the gem can't be loaded (normally because it isn't installed), it will still return a value that I can use in the manifests.

Facter.add("ibmim_installed_version") do
    setcode do
        ibmim_version = 0
        if Gem.available?('headless')
            require 'headless'
            < cut code>
        end
        ibmim_version
    end
end

patant

unread,
May 18, 2011, 4:20:09 AM5/18/11
to puppet...@googlegroups.com
Good idea!


Now I found another problem.
Some facts dosent't works when I call them explicit.

The facter shows up in the list when I run facter --puppet.
But when I call facter --puppet <facter name> it dosen't give me the value that I got in the list. Returns nothing.

"facter" gives me:
---------- 
uptime => 2 days
uptime_days => 2
uptime_hours => 49
uptime_seconds => 178750
virtual => physical

"facter uptime_seconds"
gives me nothing.

"facter -v"
1.5.6

Patrick

unread,
May 18, 2011, 11:18:02 AM5/18/11
to puppet...@googlegroups.com

I've seen a problem similar to this, and with that problem, the puppet fact works just fine. So I'd test it in puppet and ignore the problem if puppet is fine.

Felix Frank

unread,
May 24, 2011, 6:29:22 AM5/24/11
to puppet...@googlegroups.com

IIRC the reason is that the fact doesn't live in a file called
<factname>.rb. Is this the case here?

Otherwise I second Patrick's notion: Ignore the commandline weirdness
and go ahead.

Regards,
Felix

patant

unread,
May 24, 2011, 6:53:30 AM5/24/11
to puppet...@googlegroups.com
If I remove the extension .rb the facter dosen't work. So that's not the issue.

/Patrik
Reply all
Reply to author
Forward
0 new messages