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 client version: 14.12.9-1 OS Version: Ubuntu 16.04 LTS
Any missing steps?
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.
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.
as you can see,
Chef::Rest
is deprecatedso i assume that you are using an old chef version, so for the remedy i will be using chef version 12.6: