Knife bootstrap alter gem path


#1

Hello

I have a server that was manually configured and tweaked. I want to install
chef on it so I can gradually automate some stuff on it. So, cloned it,
knife bootstrap, I have a registered node in Chef.

But then, the Sinatra apps running on the server throw errors: they can’t
find the gem for Sinatra (and the other dependancies).

Comparing the config of my two servers, I see that my original VM had :

  • GEM PATHS:
    • /var/lib/gems/1.8
    • /home/ubuntu/.gem/ruby/1.8

and my chef-ized now have:

  • GEM PATHS:
    • /usr/lib/ruby/gems/1.8
    • /home/ubuntu/.gem/ruby/1.8

So:

  • Why is Chef altering the gem path?

  • Gem newbie question: How can I fix this? What is the “correct” way to
    manage this system-wide? Adding a GEM_PATH environment variable in
    /etc/profile? Or is there a better way?

Thanks for any pointers

Benoit


#2

On Wed, Nov 23, 2011 at 11:39 AM, Benoit Caron benoit@patentemoi.ca wrote:

Comparing the config of my two servers, I see that my original VM had :

  • GEM PATHS:
    • /var/lib/gems/1.8
    • /home/ubuntu/.gem/ruby/1.8
      and my chef-ized now have:
  • GEM PATHS:
    • /usr/lib/ruby/gems/1.8
    • /home/ubuntu/.gem/ruby/1.8
      So:
  • Why is Chef altering the gem path?
  • Gem newbie question: How can I fix this? What is the “correct” way to
    manage this system-wide? Adding a GEM_PATH environment variable in
    /etc/profile? Or is there a better way?

From the paths, I presume you’re using Ubuntu which relies heavily on
packages from the Debian project which adheres pretty strictly to its
collective interpretation of the Filesystem Hierarchy Standard (FHS).
The FHS specifies that /usr should be able to be mounted read-only and
shared to network clients. The version of Rubygems that ships with
Debian and Ubuntu install to /var as it is debian policy that all
files under /usr be managed by a debian package; as rubygems installs
additional files (the gems) outside of the packaging, it is moved to
/var [1]. This is the cause for the disputed location of binaries in
/var/lib/gems/1.8/bin [2], although in Wheezy and later,
/usr/local/bin will be used.

Historically the versions of Rubygems shipped with Debian and Ubuntu
were too old and had too many bugs for reliable use with Chef, so
we’ve recommended installing Rubygems from source. The default knife
bootstrap template installs Rubygems from source [3], which defaults
to installing in /usr/lib.

The “correct” installation method becomes a matter of preference. If
you prefer debian packages, you could modify a bootstrap template from
the one included for installing on Ubuntu 10.04 (Lucid) using our apt
repository [4]. You can create custom bootstrap templates and specify
them to the knife bootstrap command using the ‘-d DISTRO’ flag.
Additional information on where to locate these files is available on
the wiki:

http://wiki.opscode.com/display/chef/Knife+Bootstrap

Bryan

[1] http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=448639
[2] http://lists.debian.org/debian-ruby/2011/05/msg00104.html
[3] https://github.com/opscode/chef/blob/master/chef/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb
[4] https://github.com/opscode/chef/blob/master/chef/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb


#3

On Wed, Nov 23, 2011 at 12:50 PM, Bryan McLellan btm@loftninjas.org wrote:

On Wed, Nov 23, 2011 at 11:39 AM, Benoit Caron benoit@patentemoi.ca
wrote:

Comparing the config of my two servers, I see that my original VM had :

  • GEM PATHS:
    • /var/lib/gems/1.8
    • /home/ubuntu/.gem/ruby/1.8
      and my chef-ized now have:
  • GEM PATHS:
    • /usr/lib/ruby/gems/1.8
    • /home/ubuntu/.gem/ruby/1.8
      So:
  • Why is Chef altering the gem path?
  • Gem newbie question: How can I fix this? What is the “correct” way to
    manage this system-wide? Adding a GEM_PATH environment variable in
    /etc/profile? Or is there a better way?

From the paths, I presume you’re using Ubuntu which relies heavily on
packages from the Debian project which adheres pretty strictly to its
collective interpretation of the Filesystem Hierarchy Standard (FHS).
The FHS specifies that /usr should be able to be mounted read-only and
shared to network clients. The version of Rubygems that ships with
Debian and Ubuntu install to /var as it is debian policy that all
files under /usr be managed by a debian package; as rubygems installs
additional files (the gems) outside of the packaging, it is moved to
/var [1]. This is the cause for the disputed location of binaries in
/var/lib/gems/1.8/bin [2], although in Wheezy and later,
/usr/local/bin will be used.

Yes, this is on Ubuntu 10.10.

Historically the versions of Rubygems shipped with Debian and Ubuntu
were too old and had too many bugs for reliable use with Chef, so
we’ve recommended installing Rubygems from source. The default knife
bootstrap template installs Rubygems from source [3], which defaults
to installing in /usr/lib.

Ok, make sense: that’s what I usually do. This server was setup before my
move to Chef.

The “correct” installation method becomes a matter of preference. If
you prefer debian packages, you could modify a bootstrap template from
the one included for installing on Ubuntu 10.04 (Lucid) using our apt
repository [4]. You can create custom bootstrap templates and specify
them to the knife bootstrap command using the ‘-d DISTRO’ flag.
Additional information on where to locate these files is available on
the wiki:

http://wiki.opscode.com/display/chef/Knife+Bootstrap

Good to know: with only one node (that will soon be rebuild) it does not
make much sense, but in the future it can be usefull.

For the record, I’ve fixed my problem by simply adding:

SetEnv GEM_PATH /var/lib/gems/1.8:$GEM_PATH

in /etc/apache2/mods-enabled/passenger.conf

Thanks a lot for all the references!

Benoit