自从我从Puppet 3.8升级到Puppet 4.2后,我的模块出现了一些麻烦。看起来它无法加载gemfiles。 这是我收到的错误消息:
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
我使用以下命令应用清单:
$ puppet apply manifests/mytest.pp --modulepath=~/tmp/modules/ --debug
这是清单代码:
$ cat manifests/mytest.pp
test {"mytest": }
提供商代码:
$ 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
输入代码:
$ 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
我正在测试流浪盒的版本1.0.2(centos-6.6-64-puppet)
Puppet版本:
$ puppet --version
4.2.1
RubyGems vesion:
$ gem --version
1.3.7
使用Yum安装rest-client gem(rubygem-rest-client.noarch):
$ gem which rest-client
/usr/lib/ruby/gems/1.8/gems/rest-client-1.6.1/lib/rest-client.rb
目录结构:
$ tree
.
├── manifests
│ └── mytest.pp
└── modules
└── test
└── lib
└── puppet
├── provider
│ └── test
│ └── test.rb
└── type
└── test.rb
你有这个问题吗?任何想法如何解决?
答案 0 :(得分:1)
我终于找到了原因! Puppet代理附带了自己的Ruby和Gem二进制文件,它们位于/ opt / puppetlabs / puppet / bin /
执行此命令:
$ facter rubysitedir rubyversion
rubysitedir => /opt/puppetlabs/puppet/lib/ruby/site_ruby/2.1.0
rubyversion => 2.1.6
我注意到它指向的目录与标准位置不同。
$ which ruby
/usr/bin/ruby
$ ruby --version
ruby 1.8.7 (2013-06-27 patchlevel 374) [x86_64-linux]
为了解决这个问题,我使用了puppet 4附带的相同gem来安装rest-client:
sudo /opt/puppetlabs/puppet/bin/gem install rest-client