[RESOLVED] Cannot load Ruby Gem on node, but can in Test Kitchen?


#1

Used chef_gem to install Ruby-Kafka gem with no errors:

package_name ruby-kafka ruby-kafka
version 0.3.16
source /var/chef/cache/ruby-kafka-0.3.16.gem

but when attempting to use gem I get load error:
#<LoadError: cannot load such file – kafka> had an error

gem is installed:
$ gem list
ruby-kafka (0.3.16)

$ /opt/chef/embedded/bin/gem env
RubyGems Environment:

  • RUBYGEMS VERSION: 2.5.2
  • RUBY VERSION: 2.1.6 (2015-04-13 patchlevel 336) [x86_64-linux]
  • INSTALLATION DIRECTORY: /opt/chef/embedded/lib/ruby/gems/2.1.0
  • USER INSTALLATION DIRECTORY: /home/xxx/.gem/ruby/2.1.0
  • RUBY EXECUTABLE: /opt/chef/embedded/bin/ruby
  • EXECUTABLE DIRECTORY: /opt/chef/embedded/bin
  • SPEC CACHE DIRECTORY: /home/xxx/.gem/specs
  • SYSTEM CONFIGURATION DIRECTORY: /opt/chef/embedded/etc
  • RUBYGEMS PLATFORMS:
    • ruby
    • x86_64-linux
  • GEM PATHS:
    • /opt/chef/embedded/lib/ruby/gems/2.1.0
    • /home/xxx/.gem/ruby/2.1.0
  • GEM CONFIGURATION:
    • :update_sources => true
    • :verbose => true
    • :backtrace => false
    • :bulk_threshold => 1000
  • REMOTE SOURCES:
  • SHELL PATH:
    • /usr/lib64/qt-3.3/bin
    • /usr/local/bin
    • /bin
    • /usr/bin
    • /usr/local/sbin
    • /usr/sbin
    • /sbin
    • /opt/CA/SharedComponents/bin
    • /home/xxx/bin

Nothing is installed in local dir ’ /home/xxx/.gem’

The code installing and calling Kafka works when run in Test Kitchen, but not on actual node?

running chef-12.7.2


#2

LoadError: had an error:
cannot load such file – kafka


#3

Appears to be a Chef defect that was fixed in a later version - Test Kitchen VM has newer version of chef-client (12.14.89).

Fixed by calling Gem::clear_paths:
require 'rubygems’
Gem::clear_paths
require ‘kafka’

Still not sure why other gems work and not Ruby-Kafka gem - all gems installed at same location.