sous-chefs / ruby_rbenv

Development repository for the ruby_rbenv cookbook
https://supermarket.chef.io/cookbooks/ruby_rbenv
Apache License 2.0
331 stars 251 forks source link

unable to install 1.9.3-p286 with user recipe on vagrant #18

Closed viddo closed 11 years ago

viddo commented 11 years ago

I am trying to install a newer version of ruby using this recipe but can not figure out what is not correctly setup. I have the following setup in my Vagrantfile:

config.vm.provision :chef_solo do |chef|
    chef.cookbooks_path = "./cookbooks"

    chef.add_recipe "build-essential"
    chef.add_recipe "git"
    chef.add_recipe "ruby_build"
    chef.add_recipe "rbenv::vagrant"
    chef.add_recipe "rbenv::user"

    chef.json = {
      'rbenv' => {
        'user_installs' => [{
          'user' => 'vagrant',
          'rubies' => [ '1.9.3-p286' ],
          'global' => '1.9.3-p286',
          'gems'   => {
            '1.9.3-p286' => [
              { 'name'   => 'bundler' }
            ]
          }
        }]
      }
    }

When doing vagrant up it fails with the following output:

------------------
# Declared in /tmp/vagrant-chef-1/chef-solo-1/cookbooks/rbenv/providers/script.rb:28:in `class_from_file'

script("rbenv install 1.9.3-p286 (vagrant)") do
  retry_delay 2
  environment {"RBENV_ROOT"=>"/home/vagrant/.rbenv", "USER"=>"vagrant", "HOME"=>"/home/vagrant"}
  user "vagrant"
  returns [0]
  command "\"bash\"  \"/tmp/chef-script20121113-2372-d1vh3l-0\""
  retries 0
  code "export RBENV_ROOT=\"/home/vagrant/.rbenv\"\nexport PATH=\"${RBENV_ROOT}/bin:$PATH\"\neval \"$(rbenv init -)\"\n\nrbenv shell global\n\nrbenv install 1.9.3-p286\n"
  action "run"
  cookbook_name :rbenv
  interpreter "bash"
  backup 5
end

[2012-11-13T10:28:49+01:00] ERROR: Running exception handlers
[2012-11-13T10:28:49+01:00] ERROR: Exception handlers complete
[2012-11-13T10:28:49+01:00] FATAL: Stacktrace dumped to /tmp/vagrant-chef-1/chef-stacktrace.out
[2012-11-13T10:28:49+01:00] FATAL: Mixlib::ShellOut::ShellCommandFailed: script[rbenv install 1.9.3-p286 (vagrant)] (/tmp/vagrant-chef-1/chef-solo-1/cookbooks/rbenv/providers/script.rb line 28) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of "bash"  "/tmp/chef-script20121113-2372-d1vh3l-0" ----
STDOUT: 
STDERR: rbenv: version `global' not installed
ruby-build: definition not found: 1.9.3-p286
---- End output of "bash"  "/tmp/chef-script20121113-2372-d1vh3l-0" ----
Ran "bash"  "/tmp/chef-script20121113-2372-d1vh3l-0" returned 1
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.

From what I can see here the command issues rbenv shell global do not seem to be correct. Shouldn't it be either rbenv global *version* or rbenv shell *version*? To get further I removed this from script.rb to see if that helps but then it fails on the next command (the install part) with following output instead:

------------------

# Declared in /tmp/vagrant-chef-1/chef-solo-1/cookbooks/rbenv/providers/script.rb:28:in `class_from_file'

script("rbenv install 1.9.3-p286 (vagrant)") do
  retry_delay 2
  environment {"RBENV_ROOT"=>"/home/vagrant/.rbenv", "HOME"=>"/home/vagrant", "USER"=>"vagrant"}
  user "vagrant"
  returns [0]
  command "\"bash\"  \"/tmp/chef-script20121113-2365-16h6kal-0\""
  retries 0
  code "export RBENV_ROOT=\"/home/vagrant/.rbenv\"\nexport PATH=\"${RBENV_ROOT}/po:$PATH\"\neval \"$(rbenv init -)\"\n\nrbenv install 1.9.3-p286\n"
  action "run"
  cookbook_name :rbenv
  interpreter "bash"
  backup 5
end

[2012-11-13T10:46:47+01:00] ERROR: Running exception handlers
[2012-11-13T10:46:47+01:00] ERROR: Exception handlers complete
[2012-11-13T10:46:47+01:00] FATAL: Stacktrace dumped to /tmp/vagrant-chef-1/chef-stacktrace.out
[2012-11-13T10:46:47+01:00] FATAL: Mixlib::ShellOut::ShellCommandFailed: script[rbenv install 1.9.3-p286 (vagrant)] (/tmp/vagrant-chef-1/chef-solo-1/cookbooks/rbenv/providers/script.rb line 28) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '127'
---- Begin output of "bash"  "/tmp/chef-script20121113-2365-16h6kal-0" ----
STDOUT: 
STDERR: /tmp/chef-script20121113-2365-16h6kal-0: line 3: rbenv: command not found
/tmp/chef-script20121113-2365-16h6kal-0: line 5: rbenv: command not found
---- End output of "bash"  "/tmp/chef-script20121113-2365-16h6kal-0" ----
Ran "bash"  "/tmp/chef-script20121113-2365-16h6kal-0" returned 127

So, for the chef instance running it do not actually seem to have rbenv set. If I vagrant ssh after these failures rbenv is set though. Could this be a problem with the rehash, as was discovered a few months back (issue #5)?

Btw, I spotted the same issue of vagrant ruby default path that was fixed on chef-rvm should also be an issue on this recipe, https://github.com/fnichol/chef-rvm/pull/134 That did no difference for this problem though.

Not sure how to proceed from here so I am grateful for any help I can get. :)

Using:

vpereira commented 11 years ago

just as info. I have the same problem. My config is very similar to yours:

config.vm.provision :chef_solo do |chef|
    chef.cookbooks_path = "cookbooks"
    chef.roles_path = "roles"
    chef.add_recipe "apt"
    chef.add_recipe "build-essential"
    chef.add_recipe "zlib"
    chef.add_recipe "mongodb::10gen_repo"
    chef.add_recipe "mongodb::default"
    chef.add_recipe "ruby_build::default"
    chef.add_recipe "rbenv::vagrant"
    chef.add_recipe "rbenv::user"
    chef.add_recipe "apache2"
    chef.add_recipe "passenger_apache2"
    #chef.add_recipe "passenger"
    chef.json = {
      'rbenv' => {
        'user_installs' =>  [
          {
            'user'   => 'vagrant',
            'rubies' =>['1.9.3-p286'],
            'global' => '1.9.3-p286',
            'gems' => {
              '1.9.3-p286' => [
                {'name' => 'bundler' },
                {'name' => 'passenger'}
              ]
             }
          }
        ]
      }
    }
  end

The recipe fails, but if i do a ssh into the vm and do a "rbenv-install 1.9.3-p286" i'm able to install it.. so no missing requirement.

viddo commented 11 years ago

In the end it seems like the issue is related to having an existing VM (with rbenv installed with previous version) and modifying the Vagrantfile configuration to use the newer version. After re-creating (i.e. vagrant destroy && vagrant up) it works for me.

viddo commented 11 years ago

A little more investigating, I found this issue on the rbenv itself which seems very related: https://github.com/sstephenson/rbenv/pull/293

For now I use the revision mentioned in this pull-request to install the rbenv, and it seems to work as expected now.

I.e. in my Cheffile:

cookbook 'rbenv',
  :git => 'https://github.com/fnichol/chef-rbenv', :ref => 'c921ab6'
mislav commented 11 years ago

Closing since this was never a bug with rbenv. I'm glad the chef-rbenv people fixed it

brandonparsons commented 11 years ago

I am actually still having issues with this... any thoughts?

I have done this:

# Install Ruby for the deployer user
include_recipe "ruby_build"

if node['user_info']['vagrant_install']
  include_recipe "rbenv::vagrant"
end

gem_array = []
node['rbenv']['gems'].each do |desired_gem|
  gem_array << {'name' => desired_gem}
end

node.set['rbenv']['user_installs'] = [
  {
    'user'    => node['user_info']['username'],
    'rubies'  => [ node['rbenv']['ruby_version'] ],
    'gems'    => {
      node['rbenv']['ruby_version'] => gem_array
    }
  }
]

include_recipe "rbenv"
include_recipe "rbenv::user"

rbenv_global node['rbenv']['ruby_version'] do
  user node['user_info']['username']
end

And originally had :

'global'  => node['rbenv']['ruby_version'],

In the node.set rather than using the LWRP:

rbenv_global node['rbenv']['ruby_version'] do
  user node['user_info']['username']
end

In both cases I'm getting the error: 'global' not installed

================================================================================
Error executing action `run` on resource 'script[rbenv install 1.9.3-p362 (deployer)]'
================================================================================

Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of "bash"  "/tmp/chef-script20121230-9144-ost2qk-0" ----
STDOUT: 
STDERR: rbenv: version `global' not installed
rbenv: no such command `install'
---- End output of "bash"  "/tmp/chef-script20121230-9144-ost2qk-0" ----
Ran "bash"  "/tmp/chef-script20121230-9144-ost2qk-0" returned 1

Resource Declaration:
---------------------
# In /tmp/chef-solo/cookbooks/rbenv/providers/script.rb

 28:   script new_resource.name do
 29:     interpreter   "bash"
 30:     code          script_code
 31:     user          new_resource.user     if new_resource.user
 32:     creates       new_resource.creates  if new_resource.creates
 33:     cwd           new_resource.cwd      if new_resource.cwd
 34:     group         new_resource.group    if new_resource.group
 35:     path          new_resource.path     if new_resource.path
 36:     returns       new_resource.returns  if new_resource.returns
 37:     timeout       new_resource.timeout  if new_resource.timeout
 38:     umask         new_resource.umask    if new_resource.umask
 39:     environment(script_environment)
 40:   end
 41: 

Compiled Resource:
------------------
# Declared in /tmp/chef-solo/cookbooks/rbenv/providers/script.rb:28:in `class_from_file'

script("rbenv install 1.9.3-p362 (deployer)") do
  interpreter "bash"
  retry_delay 2
  action "run"
  retries 0
  code "export RBENV_ROOT=\"/home/deployer/.rbenv\"\nexport PATH=\"${RBENV_ROOT}/bin:$PATH\"\neval \"$(rbenv init -)\"\n\nrbenv shell global\n\nrbenv install 1.9.3-p362\n"
  returns [0]
  cookbook_name :rbenv
  command "\"bash\"  \"/tmp/chef-script20121230-9144-ost2qk-0\""
  environment {"RBENV_ROOT"=>"/home/deployer/.rbenv", "HOME"=>"/home/deployer", "USER"=>"deployer"}
  backup 5
  user "deployer"
end

[2012-12-30T21:45:01-07:00] ERROR: Running exception handlers
[2012-12-30T21:45:01-07:00] ERROR: Exception handlers complete
[2012-12-30T21:45:02-07:00] FATAL: Stacktrace dumped to /tmp/chef-solo/chef-stacktrace.out
[2012-12-30T21:45:02-07:00] FATAL: Mixlib::ShellOut::ShellCommandFailed: script[rbenv install 1.9.3-p362 (deployer)] (/tmp/chef-solo/cookbooks/rbenv/providers/script.rb line 28) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of "bash"  "/tmp/chef-script20121230-9144-ost2qk-0" ----
STDOUT: 
STDERR: rbenv: version `global' not installed
rbenv: no such command `install'
---- End output of "bash"  "/tmp/chef-script20121230-9144-ost2qk-0" ----
Ran "bash"  "/tmp/chef-script20121230-9144-ost2qk-0" returned 1

Any thoughts?

lock[bot] commented 6 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.