0

Could someone please help with a question regarding use of a 3rd party gem with an omnibus installation running Chef recipes? I would like to use a 'p4ruby' gem that has been packaged up with omnibus and should be available for use in a recipe using

require 'P4'

I get the error

cannot load such file -- P4

In the installation directory I can see

./embedded/service/gem/ruby/2.1.0/gems/p4ruby-2015.1.0/ext/P4/p4rubyconf.h
./embedded/service/gem/ruby/2.1.0/gems/p4ruby-2015.1.0/ext/P4/p4rubydebug.h
./embedded/service/gem/ruby/2.1.0/cache/p4ruby-2015.1.0.gem
./embedded/service/gem/ruby/2.1.0/specifications/p4ruby-2015.1.0.gemspec
./embedded/service/gem/ruby/2.1.0/build_info/p4ruby-2015.1.0.info
./embedded/lib/ruby/gems/2.1.0/gems/p4ruby-2015.1.0/ext/P4/p4rubyconf.h
./embedded/lib/ruby/gems/2.1.0/gems/p4ruby-2015.1.0/ext/P4/p4rubydebug.h
./embedded/lib/ruby/gems/2.1.0/cache/p4ruby-2015.1.0.gem

I have read through the Chef docs and see that I could use chef_gem or gem_package for example

gem_package 'p4ruby' do
end

However this always tries to compile the gem and this leads to errors in our target installation environment as we cannot expect dev tools such as make and g++ to be available and we do not want to force installation of them.

How can I get Chef to 'see' this gem or to specifiy a 3rd party gem without compilation running? Is this possible?

For further info if I do use gem_package on a machine that does have make and g++ I end up with the following in the install directory (which looks slightly different than before). Is this a path issue?? I've searched all over but cannot find a solution

./embedded/service/gem/ruby/2.1.0/gems/p4ruby-2015.1.0/ext/P4/p4rubyconf.h
./embedded/service/gem/ruby/2.1.0/gems/p4ruby-2015.1.0/ext/P4/p4rubydebug.h
./embedded/service/gem/ruby/2.1.0/cache/p4ruby-2015.1.0.gem
./embedded/service/gem/ruby/2.1.0/specifications/p4ruby-2015.1.0.gemspec
./embedded/service/gem/ruby/2.1.0/build_info/p4ruby-2015.1.0.info
./embedded/lib/ruby/gems/2.1.0/gems/p4ruby-2015.1.0/ext/P4/p4rubyconf.h
./embedded/lib/ruby/gems/2.1.0/gems/p4ruby-2015.1.0/ext/P4/p4rubydebug.h
./embedded/lib/ruby/gems/2.1.0/cache/p4ruby-2015.1.0.gem
./embedded/lib/ruby/gems/2.1.0/specifications/p4ruby-2015.1.0.gemspec

Many thanks for any help

ScottW
  • 1

2 Answers2

0

How can I get Chef to 'see' this gem or to specifiy a 3rd party gem without compilation running? Is this possible?

No, if a gem has some C extension, it must be compiled and will need build tools, that's why there's the build-essential cookbook.

The differences between chef_gem and gem_package are this:

  • gem_package will install to system ruby (or default to chef embedded ruby is none present) where chef_gem will always install in chef embedded ruby.
  • gem_package run in converge phase where chef_gem run at compile time

The main reason is that chef_gem is aimed at installing gem to be used in recipes where gem_package is aimed at managing system gems for use out of chef.

Tensibai
  • 15,557
  • 1
  • 37
  • 57
0

Think I found a way of doing this...

$:.unshift *Dir[File.path('<my_path_to_gems>/**/lib')]

I can then

require 'P4'

in my recipes

ScottW
  • 1