Is it possible to install and use a Ruby distribution alongside a PC with Opscode Chef Client without one affecting the other? - ruby

I'm running chef-client on Windows, and as it happens, the Ruby distribution (1.9.3) embedded in Chef-Client is available system-wide. I believe this is necessary in order to have chef-client function properly? I have tried installing another Ruby distribution (namely, v2.0) but that seems to break Chef-Client.
What I was hoping to achieve is to have chef-client install & configure a Ruby app written against v2.0, so that I can run that app with v2 but have chef-client continue to use the embedded Ruby distribution.
Would that not be possible?

Sure, that's why Opscode is using their Omnibus packages, which ships everything required to run Chef.

Use the "gem_binary" attribute to specify the ruby distro:
gem_package "somegem" do
gem_binary "/usr/bin/gem"
action :install
end
The documentation describe the parameter as follows:
gem_binary: An attribute for the gem_package provider that is used to specify a gems binary. This attribute is useful when installing Ruby 1.9 gems while running in Ruby 1.8. By default, the same version of Ruby that is used by the chef-client will be installed.

Related

Cookbook's deep dependency requires an unavailable Ruby version. How to circumvent via chef for Amazon Linux?

I'm a non-Ruby developer using Chef 11.10 on Amazon Linux AMI 2018.03, OpsWorks Agent v.3451.
My Route53 cookbook requires fog which requires fog-brightbox which requires an unspecified version of dry-inflector whose most recent version requires Ruby version 2.4 in its gemspec.
fog is installed via chef_gem which uses a separate version of Ruby reserved for use by the Chef client only, and it is not recommended to update this Ruby version as it may disable the Opsworks Agent.
Is the only way to get around this issue to fork and host each dependency in the chain, then force an earlier version of the deep dependency?
Version 0.1.2 of the dry-inflector gem doesn't require a specific version of Ruby.
Just install the gem with that specific version as soon as possible on your machine.

Chef with omnibus using 3rd party gems

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
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.
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

How to handle different ruby version requirements between chef 10.28.0 and ohai 8.0.1

I'm trying to build a server on rackspace using chef 10.28.0, building the exact same configuration that I've built three times before without any changes. The only difference is that chef installed ohai 7.4.0 on the previous runs and this time it is installing ohai 8.0.1.
The problem is that chef 10.28.0 installs ruby 1.9.3, whereas ohai 8.0.1 requires ruby 2.0.0 or greater. From my googling I have found that chef 10 supports ruby 2.0 but installs ruby 1.9 by default. Is there any way to get chef 10 to install ruby 2.0 instead? Barring that, is there any way to get chef 10 to install ohai 7.4 instead of 8.0?
Thanks in advance.
Please use the omnibus installer packages. These include Ruby, Chef, Ohai, and all the other dependencies in a working configuration. You can download older versions of the omnibus installers from the download page:
Or you can use the -v option to the bootstrap scripts.
The answer was in the bootstrap scripts. We are using custom bootstrap scripts and the versions for ruby, chef and ohai are all in there.

Ruby command line tool crash when switch ruby version in rvm

I am trying to make an CLI tool with ruby.
My tool require some library in bundle (log4r, ...). So problem appear when i switch my ruby version (2.0.0 -> 2.1.2) or when switch gemset, some gem are not install in new ruby environment.
So how can i make my app work like vagrant, which work in every version of ruby i am using?
If you package your application as a Gem, you can include a Gemspec that describes your application. One of the things you can specify is its runtime dependencies; when the user runs gem install myapp, then the gem command will make sure it includes everything you specified (like log4r).
It will be harder to make this happen without Rubygems. You can package your application along with a defined version of Ruby and all its requirements - that's what Vagrant does - but that makes your application a larger download and means you have more to maintain. It's going to be hard work if you want to install your app system-wide and have it work with every single Ruby environment. It's far better to let the gem application install your app (whether systemwide, or via rbenv/rvm) and let that manage your dependencies for you. There's the default gems plugin for rbenv and rvm gemsets to help manage this.

Different search paths when installing Ruby via RVM

I am using Puppet together with Librarian Puppet. Puppet is installed via the system's package manager, Librarian Puppet via Ruby gem. It only works when I install Ruby (1.9.3) via Debian's package manager. When I use RVM with the identical or another version (>= 1.9.3), I get an error from Librarian, saying that it cannot find puppet. Line 4 require 'puppet' in local.rbcauses the problem in Librarian. The puppet gem-based installation is not recommended and I don't want to do it that way. After some hours debugging, I found out that Ruby's search path differs when you use the package manager or RVM. Using RVM with Ruby 2.1.2, I get:
/usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0
/usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/x86_64-linux
/usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby
/usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/vendor_ruby/2.1.0
/usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/vendor_ruby/2.1.0/x86_64-linux
/usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/vendor_ruby
/usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0
/usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/x86_64-linux
The puppet.rbis located at /usr/lib/ruby/vendor_ruby. This path is part of the search path if I install Ruby via Debian's package manager!
/usr/local/lib/site_ruby
...
/usr/lib/ruby/vendor_ruby
Is there any solution without installing puppet via gem?
librarian-puppet needs the puppet gem to parse the dependencies' Modulefile when using git and path modules. Not for Forge modules though
https://github.com/rodjek/librarian-puppet/blob/master/lib/librarian/puppet/source/local.rb#L8
https://github.com/rodjek/librarian-puppet/pull/62

Resources