chef_gem vs. gem_package


#1

from the documentation:

Warning
The chef_gem and gem_package resources are both used to install Ruby gems. For
any machine on which Chef is installed, there are two instances of Ruby. One is
the standard, system-wide instance of Ruby and the other is a dedicated
instance that is available only to Chef. Use the chef_gem resource to install
gems into the instance of Ruby that is dedicated to Chef. Use the gem_package
resource to install all other gems (i.e. install gems system-wide).

from observation:

gem_package will fall-back to chef_gem behavior if ruby isn’t on the system.
have you seen this? Am I imagining it? The problem is that you don’t get
consistent results from a recipe. If one machine has a system ruby 1.8,
another machine has chef-client (with ruby 1.9) and no system ruby, very
different things can happen with the same recipe. Should the meaning of
chef_gem vs. gem_package , and the differences between them, be more enforced?


#2

Sam,

Sounds like http://docs.opscode.com/resource.html is a bit off. Perhaps
my history is off, but if I recall chef_gem was created as a helper to
install the gem during the compilation phase and reload the gem path so
you can load said gem in your cookbook.

Reviewing


does appear to make this assumption true. chef_gem is using the same
resource to install gems, it just has the after command to reload the
gem path.

So you use gem_package if you want the gem installed during the regular
cookbook run; if you need to use the gem in your cookbooks you should
use chef_gem.

Yeah it sounds like there’s a documentation ticket in the brew for this
resource, at least my knowledge conflicts with the documentation.

Scott

On 8/5/13 5:31 AM, Sam Darwin wrote:

from the documentation:

Warning
The chef_gem and gem_package resources are both used to install Ruby gems. For
any machine on which Chef is installed, there are two instances of Ruby. One is
the standard, system-wide instance of Ruby and the other is a dedicated
instance that is available only to Chef. Use the chef_gem resource to install
gems into the instance of Ruby that is dedicated to Chef. Use the gem_package
resource to install all other gems (i.e. install gems system-wide).

from observation:

gem_package will fall-back to chef_gem behavior if ruby isn’t on the system.
have you seen this? Am I imagining it? The problem is that you don’t get
consistent results from a recipe. If one machine has a system ruby 1.8,
another machine has chef-client (with ruby 1.9) and no system ruby, very
different things can happen with the same recipe. Should the meaning of
chef_gem vs. gem_package , and the differences between them, be more enforced?

!DSPAM:51ff9b3b321631804284693!


#3

To further elaborate, using the gem_binary_location variable to
specify exactly which gem environment you want the installed gem under
(if you have multiple installations) is the way to go.
-M

On Mon, Aug 5, 2013 at 1:25 PM, Scott M. Likens scott@likens.us wrote:

Sam,

Sounds like http://docs.opscode.com/resource.html is a bit off. Perhaps my
history is off, but if I recall chef_gem was created as a helper to install
the gem during the compilation phase and reload the gem path so you can load
said gem in your cookbook.

Reviewing
https://github.com/opscode/chef/blob/11.6.0/lib/chef/resource/chef_gem.rb#L43-49
does appear to make this assumption true. chef_gem is using the same
resource to install gems, it just has the after command to reload the gem
path.

https://github.com/opscode/chef/blob/11.6.0/lib/chef/resource/gem_package.rb

So you use gem_package if you want the gem installed during the regular
cookbook run; if you need to use the gem in your cookbooks you should use
chef_gem.

Yeah it sounds like there’s a documentation ticket in the brew for this
resource, at least my knowledge conflicts with the documentation.

Scott

On 8/5/13 5:31 AM, Sam Darwin wrote:

from the documentation:

Warning
The chef_gem and gem_package resources are both used to install Ruby gems.
For
any machine on which Chef is installed, there are two instances of Ruby.
One is
the standard, system-wide instance of Ruby and the other is a dedicated
instance that is available only to Chef. Use the chef_gem resource to
install
gems into the instance of Ruby that is dedicated to Chef. Use the
gem_package
resource to install all other gems (i.e. install gems system-wide).

from observation:

gem_package will fall-back to chef_gem behavior if ruby isn’t on the
system.
have you seen this? Am I imagining it? The problem is that you don’t
get
consistent results from a recipe. If one machine has a system ruby 1.8,
another machine has chef-client (with ruby 1.9) and no system ruby, very
different things can happen with the same recipe. Should the meaning
of
chef_gem vs. gem_package , and the differences between them, be more
enforced?

!DSPAM:51ff9b3b321631804284693!


#4

On Mon, Aug 5, 2013 at 8:31 AM, Sam Darwin samuel.d.darwin@gmail.com wrote:

gem_package will fall-back to chef_gem behavior if ruby isn’t on the system.
have you seen this? Am I imagining it? The problem is that you don’t get
consistent results from a recipe. If one machine has a system ruby 1.8,
another machine has chef-client (with ruby 1.9) and no system ruby, very
different things can happen with the same recipe. Should the meaning of
chef_gem vs. gem_package , and the differences between them, be more enforced?

chef_gem is for installing Gems you want to use in your Chef recipes.
It will be installed to the Ruby that Chef is running under early in
the Chef run so you can use that gem immediately.

gem_package is for installing Rubygems that you want to use on your
system (e.g. Rails). It will look for a gem command in your path and
fail if it can’t find one. If the Ruby that you run Chef under is the
same as the first one in your path, then gem_package and chef_gem
install the gem to the same place, but chef_gem does so earlier in a
Chef run (and runs Gem.clear_paths to ensure the gem is loaded to the
current Ruby).

As long as you’re using the Omnibus installs, gem_package should fail
if you haven’t installed Ruby on your system.

Bryan

[vagrant@freebsd91 ~] pkg_info | grep ruby [vagrant@freebsd91 ~] pkg_info | grep ohai
[vagrant@freebsd91 ~] cat foo.rb gem_package "ohai" [vagrant@freebsd91 ~] sudo chef-apply foo.rb
Recipe: (chef-apply cookbook)::(chef-apply recipe)

  • gem_package[ohai] action install
    ================================================================================
    Error executing action install on resource ‘gem_package[ohai]’
    ================================================================================

Chef::Exceptions::FileNotFound

Unable to find ‘gem’ binary in path:
/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/home/vagrant/bin

[snip]