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?
Sounds like About Resources 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?
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 About Resources 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.
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?
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.