Ask Your Question
0

Could not load ruby gem from Puppet provider

asked 2015-08-13 08:02:15 -0500

lukeskywalker gravatar image

updated 2015-08-13 10:56:08 -0500

I'm having some troubles with my modules since I've upgraded from Puppet 3.8 to Puppet 4.2. Looks like it's unable to load gemfiles. Here is the error message I get:

Error: Could not autoload puppet/provider/test/test: cannot load such file -- rest-client
Error: Could not autoload puppet/type/test: Could not autoload puppet/provider/test/test: cannot load such file -- rest-client
Error: Evaluation Error: Error while evaluating a Resource Statement, Could not autoload puppet/type/test: Could not autoload puppet/provider/test/test: cannot load such file -- rest-client at /home/vagrant/tmp/manifests/mytest.pp:1:1 on node

I apply the manifest with the command:

$ puppet apply manifests/mytest.pp --modulepath=~/tmp/modules/ --debug

Here is the manifest code:

$ cat manifests/mytest.pp 
test {"mytest": }

Provider code:

$ cat modules/test/lib/puppet/provider/test/test.rb 
require 'rubygems'
require 'rest-client'

Puppet::Type.type(:test).provide(:test) do
  desc "Just testing"

  def create
    puts "Entered create "
  end

  def destroy
  end

  def exists?
   return false
  end
end

Type code:

$ cat modules/test/lib/puppet/type/test.rb
Puppet::Type.newtype(:test) do

  @doc = "Just testing."

  ensurable do
    defaultvalues
    defaultto :present
  end

  newparam(:name, :namevar => true) do
    desc 'An arbitrary name used as the identity of the resource.'
  end
end

I'm testing on version 1.0.2 of vagrant Box (centos-6.6-64-puppet)

Puppet version:

$ puppet --version
4.2.1

RubyGems vesion:

$ gem --version
1.3.7

rest-client gem installed using Yum (rubygem-rest-client.noarch):

$ gem which rest-client
/usr/lib/ruby/gems/1.8/gems/rest-client-1.6.1/lib/rest-client.rb

Directory structure:

$ tree
.
├── manifests
│   └── mytest.pp
└── modules
    └── test
        └── lib
            └── puppet
                ├── provider
                │   └── test
                │       └── test.rb
                └── type
                    └── test.rb

Did you have this issue ? any idea how to solve it ?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2015-08-13 13:31:23 -0500

lukeskywalker gravatar image

I've finally found the reason! Puppet agent is shipped with its own Ruby and Gem binaries, and they lay in /opt/puppetlabs/puppet/bin/

by executing this command:

$ facter rubysitedir rubyversion
rubysitedir => /opt/puppetlabs/puppet/lib/ruby/site_ruby/2.1.0
rubyversion => 2.1.6

I noticed that it points to a different directory than the standard location.

$ which ruby
/usr/bin/ruby
$ ruby --version
ruby 1.8.7 (2013-06-27 patchlevel 374) [x86_64-linux]

To solve the issue, I used the same gem shipped with puppet 4 to install rest-client:

sudo /opt/puppetlabs/puppet/bin/gem install rest-client
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2015-08-13 08:02:15 -0500

Seen: 1,288 times

Last updated: Aug 13 '15