poseid
poseid

Reputation: 7156

How to debug RVM setup from Chef and Vagrant?

I got RVM setup with Chef-solo on a Vagrant VM just fine, however I am confused on why bundler can not be found in the rails project.

So, after provisioning I see:

Last login: Thu Oct  4 15:23:58 2012 from 10.0.2.2
vagrant@vm:~$ ruby -v
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-linux]
vagrant@vm:~$ gem list

*** LOCAL GEMS ***

bigdecimal (1.1.0)
bundler (1.3.2)
daemon_controller (1.1.1)
fastthread (1.0.7)
io-console (0.3)
json (1.5.4)
minitest (2.5.1)
passenger (3.0.18)
rack (1.5.2)
rake (10.0.3, 0.9.2.2)
rdoc (3.9.4)
rubygems-bundler (1.1.1)
rvm (1.11.3.6)

Going to the project directory I see:

vagrant@vm:~$ cd /www/vm/rails/current/
==============================================================================
= NOTICE                                                                     =
==============================================================================
= RVM has encountered a new or modified .rvmrc file in the current directory =
= This is a shell script and therefore may contain any shell commands.       =
=                                                                            =
= Examine the contents of this file carefully to be sure the contents are    =
= safe before trusting it! ( Choose v[iew] below to view the contents )      =
==============================================================================
Do you wish to trust this .rvmrc file? (/www/vm/rails/current/.rvmrc)
y[es], n[o], v[iew], c[ancel]> y
mkdir: cannot create directory `/usr/local/rvm/gems/ruby-1.9.3-p327@vm': Permission denied
gemset vm is not existing, creating.
mkdir: cannot create directory `/usr/local/rvm/gems/ruby-1.9.3-p327@vm': Permission denied
mkdir: cannot create directory `/usr/local/rvm/gems/ruby-1.9.3-p327@vm': Permission denied

But now, bundle can not be found anymore, and I also have problems to activate RVM... any ideas how to debug this?

$ rvm use ruby-1.9.3-p327
Please note that `rvm gem ...` was removed, try `gem  ` or `rvm all do gem  ` instead. ( see: 'rvm usage' )

PS my node json is basically this: https://github.com/mulderp/chef-rails-stack

Upvotes: 0

Views: 750

Answers (1)

mpapis
mpapis

Reputation: 53158

For debugging I use https://github.com/mpapis/rvm-binary/blob/master/cookbooks/binary/recipes/default.rb#L11 :

class Chef::Resource::Script
  def log_code command
    if Chef::Config[:log_level] == :debug
      code "{ #{command}; _ret=$?; echo \"Exit status was $_ret.\"; exit $_ret; } 2>&1 |
tee /var/log/#{@command.to_s.gsub(/ /,"_")}.log; exit ${PIPESTATUS[0]}"
    else
      code command
    end
  end
end

and then instead of code use log_code, it will save logs in /var/log/#{@command.to_s.gsub(/ /,"_")}.log

as for easy integration of RVM with Chef check https://gist.github.com/sevos/5076747 :

deploy_user = node[:deploy][:user]
deploy_user_home = File.join('/', 'home', deploy_user)
rvm_version = "head"

execute "install_rvm_for_deploy_user" do
  user deploy_user
  command "curl -L https://get.rvm.io | bash -s #{rvm_version}"
  environment "HOME" => deploy_user_home
  creates "#{deploy_user_home}/.rvm"
end

node['buildpack']['ruby_versions'].each do |ruby_version|
  execute "install_rvm_ruby_#{ruby_version}" do
    user deploy_user
    environment "HOME" => deploy_user_home
    command "#{deploy_user_home}/.rvm/bin/rvm install #{ruby_version} --autolibs=3"
  end
end

file "#{deploy_user_home}/.rvmrc" do
  content 'export rvm_trust_rvmrcs_flag=1'
  owner deploy_user
  mode 0644
end

Upvotes: 1

Related Questions