Chiefwarpaint
Chiefwarpaint

Reputation: 673

RVM Ruby Install Breaks Chef-Client On Bootstrapped Node

I have a Red Hat Enterprise Linux Server release 6.7 node that I have bootstrapped with CHEF. I've successfully executed multiple cookbooks/recipes on this node. Now I need to setup this node to run Ruby On Rails applications.

I have a cookbook with recipes that successfully ::

  1. installs RVM
  2. installs Ruby v2.2

The Problem

After RVM installs Ruby, the CHEF-Client on the bootstrapped node no longer works. Regardless of what Cookbook/Recipe(s) I try to run, I get the following output ::

PS C:\Users\JW031544\workspace\CHEF\chef-repo> knife ssh dh2vrtooldev01 "chef-client -o recipe[MY_COOKBOOK::default]" --manual-list --ssh-user MY_USER --ssh-password "MY_PASS"

dh2vrtooldev01 Ignoring executable-hooks-1.3.2 because its extensions are not built.  Try: gem pristine executable-hooks --version 1.3.2
dh2vrtooldev01 Ignoring gem-wrappers-1.2.7 because its extensions are not built.  Try: gem pristine gem-wrappers --version 1.2.7
dh2vrtooldev01 Ignoring nokogiri-1.6.8.1 because its extensions are not built.  Try: gem pristine nokogiri --version 1.6.8.1
dh2vrtooldev01 /opt/chef/embedded/lib/ruby/site_ruby/2.3.0/rubygems/dependency.rb:308:in `to_specs': Could not find 'addressable' (= 2.4.0) among 45 total gem(s) (Gem::MissingSpecError)
dh2vrtooldev01 Checked in 'GEM_PATH=/usr/local/rvm/gems/ruby-2.2.4:/usr/local/rvm/gems/ruby-2.2.4@global', execute `gem env` for more information
dh2vrtooldev01  from /opt/chef/embedded/lib/ruby/site_ruby/2.3.0/rubygems/dependency.rb:320:in `to_spec'
dh2vrtooldev01  from /opt/chef/embedded/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_gem.rb:65:in `gem'
dh2vrtooldev01  from /usr/bin/chef-client:4:in `<main>'

If I go onto the node and tell RVM to remove that version of Ruby, then the CHEF-Client will begin working again just fine.


The Question

Does anyone have any idea why CHEF-Client suddenly forgets how to run once RVM installs a version of Ruby?


Source Code

(default.rb)

include_recipe 'abl_rails::rvm_install'
include_recipe 'abl_rails::ruby_install'

(rvm_install.rb)

# Install RVM (if it doesn't already exist)
execute 'install_rvm' do
  cwd '/root/'
  command 'curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -; curl -L get.rvm.io | bash -s stable'
  not_if {::File.exists?('/etc/profile.d/rvm.sh')}
end

(ruby_install.rb)

# Install Ruby
bash 'install_ruby' do
  cwd '/root/'
   code <<-EOH
    source /etc/profile.d/rvm.sh;
    rvm install #{node['ruby_version']};
  EOH
  not_if "source /etc/profile.d/rvm.sh; ruby --version | grep #{node['ruby_version']}", :cwd => '/root'
  notifies :run, "bash[set_default_rvm_ruby]", :immediately
end

# Set the default Ruby version in RVM
bash "set_default_rvm_ruby" do
  cwd '/root'
  code <<-EOH
    source /etc/profile.d/rvm.sh;
    rvm use #{node['ruby_version']} --default;
  EOH
  action :run
end

Upvotes: 2

Views: 512

Answers (2)

lamont
lamont

Reputation: 3974

This may be fixed in chef-client 12.17.x so that chef-client correctly breaks out of the RVM environment:

Related Chef bugs:

https://github.com/chef/appbundler/pull/24

https://github.com/chef/chef/issues/5589

If it is still broken after 12.17.x (when ::Gem.clear_paths exists in the /opt/chef/bin/chef-client appbundler binstub) then a new issue should get cut against appbundler.

(As an RVM user, though, I would not recommend using it for running production services, but I find it very nice to use in a dev workstation kind of environment -- but YMMV).

Upvotes: 0

Augusto
Augusto

Reputation: 29927

rvm overrides the cd internal function with a custom function, and that is causing the error. Try removing rvm and use a different ruby manager such as rbenv.

Check this blog post for other differences between rvm and rbenv : http://jonathan-jackson.net/rvm-and-rbenv

I'll be honest, I had the same issue before (but not with chef), read a bit more about rvm and decided that it was not the right tool for me. I'm sure there must be a way to make rvm play nicely, but I decided it was not worth the effort.

Upvotes: 2

Related Questions