简体   繁体   中英

Puppet custom facts - uninitialized constant Facter (NameError)

I'm really sorry if I've missed something, and this has already been answered, I've searched this site, and Google, but can't find anything anyway, here goes.

I'm running Ruby 1.8 and Puppet 2.7. I'm new to both, but I've done a fair amount of work with Puppet over the last couple of weeks, touch wood without bringing my site down :)

I would now like to write some custom facts. I've been experimenting with the instruction found on the Puppet documentation site . I've written a hardware_platform.rb as below:

# hardware_platform.rb

Facter.add("hardware_platform") do
  setcode do
    Facter::Util::Resolution.exec('/bin/uname -i')
  end
end

I guess I'm supposed to run it like this:

# ruby hardware_platform.rb

But when I do, I get this error:

hardware_platform.rb:3: uninitialized constant Facter (NameError)

Does anyone know what might be going wrong here? I need to get past this before I can move on...

Thanks

You're probably missing a require 'facter' at the top of the script. Also verify that the facter gem is installed by running gem install facter .

If you are testing this code anywhere other than the ruby lib directory that puppet will look for, then set the RUBYLIB first. eg testing under a dir name /path/to/dir , create lib/ruby/facter/hardware_platform.rb

and you can then,

export RUBYLIB=/path/to/dir/lib/ruby

then, you can run

facter hardware_platform

that should give you a correct result.

As @lucas_clemente says, you also need to check if facter is installed in your system. If you are using yum, just check/install it using,

yum list facter 

it will result something like this if installed or it will show the version exists in your repo if not installed :

facter.x86_64        1:1.6.12-2.el5           installed

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM