PapelPincel
PapelPincel

Reputation: 4393

Could not load ruby gem from Puppet provider

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 ?

Upvotes: 1

Views: 1112

Answers (1)

PapelPincel
PapelPincel

Reputation: 4393

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

Upvotes: 2

Related Questions