“无法加载这样的文件-厨师/休息”当“需要'厨师/休息'”时
尝试编写第一个程序以通过API访问Chef服务器。以下> https://docs.chef.io/api_chef_server.html#examples 上的示例程序>应该有两行代码包含 chef :: rest
库。
Trying to write first program to access chef server via API. Following example program on https://docs.chef.io/api_chef_server.html#examples there supposed to be two lines of code to include chef::rest
library.
require 'chef'
require 'chef/rest'
但是代码失败并出现错误
but the code failed with error
Traceback (most recent call last):
2: from ./rest.rb:4:in `<main>'
1: from /opt/chef/embedded/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/opt/chef/embedded/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- chef/rest (LoadError)
Chef客户端版本:14.12.9-1
操作系统版本:Ubuntu 16.04 LTS
Chef client version: 14.12.9-1 OS Version: Ubuntu 16.04 LTS
是否缺少任何步骤?
您没有分享是否使用厨师库作为ap您的食谱的艺术性或作为依赖厨师库的另一个程序的一部分。
you did not share whether you use chef libraries as a part of your cookbooks or as a part of another program that depended on the chef libraries.
如果您是第二种情况,即在食谱上下文之外,则确保您正在使用Gemfile来管理厨师库需求,然后使用捆绑程序执行程序。
if you are at the second case, i.e. outside of a cookbook context, then make sure that you are using Gemfile to manage your chef libraries requirement, then execute your program using bundler.
如您所见, Chef :: Rest
已弃用
as you can see, Chef::Rest
is deprecated
Chef :: REST
类将被删除。Chef :: REST
在12.7.2中已弃用,并将在Chef 13中删除。
The
Chef::REST
class will be removed.Chef::REST
was deprecated in 12.7.2, and will be removed in Chef 13.
如果编写代码设计为在Chef内部运行(例如在食谱或小刀插件中),过渡到使用 Chef :: ServerAPI
。在大多数情况下,这就像创建一个 Chef :: ServerAPI
实例而不是一个 Chef :: REST
实例一样简单。
If writing code designed to be run internally to Chef, for example in a cookbook or a knife plugin, transition to using Chef::ServerAPI
. In most cases this is as simple as creating a Chef::ServerAPI
instance rather than a Chef::REST
one.
如果要编写代码与其他代码与Chef Server进行交互,请移至 chef-api
gem。
If writing code to interact with a Chef Server from other code, move to the chef-api
gem.
所以我假设您使用的是旧厨师版,因此,我将使用厨师版12.6:
so i assume that you are using an old chef version, so for the remedy i will be using chef version 12.6:
$ cat Gemfile
# frozen_string_literal: true
source "https://rubygems.org"
gem 'chef', '12.6.0'
$ cat foo.rb
require 'chef'
require 'chef/rest'
$ bundle install
...
Bundle complete! 1 Gemfile dependency, 46 gems now installed.
$ bundle exec ruby foo.rb