Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #16, load rbenv environment after install #42

Merged
merged 2 commits into from Mar 3, 2014

Conversation

msaffitz
Copy link
Contributor

Fixes #16, such that the environment is loaded after install and available for subsequent gem installs

@guidomb
Copy link

guidomb commented Apr 5, 2013

I am using your fork but I still have the same issue. It fails randomly, I dont know why.

Here is my rbenv recipe

include_recipe 'ruby_build'
include_recipe 'rbenv::user_install'

version     = node['ruby']['version']
rbenv_user  = node['rbenv']['owner']

rbenv_ruby version do
  user rbenv_user
  action :install
end

rbenv_global version do
  user rbenv_user
  action :create
end

rbenv_gem "bundler" do
  rbenv_version   version
  user rbenv_user
  action :install
end

and this is my Berksfile

site :opscode

# External cookbooks
cookbook 'apt'
cookbook 'database'
cookbook 'rbenv', git: 'git://github.com/apptentive/chef-rbenv'
cookbook 'imagemagick'
cookbook 'nginx'

# Local cookbooks
cookbook 'set_locale',              path: 'config/chef/cookbooks/set_locale'
cookbook 'postgresql_server_utf8',  path: 'config/chef/cookbooks/postgresql_server_utf8'
cookbook 'rails_env',               path: 'config/chef/cookbooks/rails_env'

this is the exception I get sometimes. The bizarre thing is that sometimes it works/

[2013-04-05T19:37:26+00:00] INFO: Processing rbenv_script[rbenv install 1.9.3-p392 (vagrant)] action nothing (/tmp/vagrant-chef-1/chef-solo-1/cookbooks/rbenv/providers/ruby.rb line 61)
[2013-04-05T19:37:26+00:00] INFO: Processing script[rbenv install 1.9.3-p392 (vagrant)] action run (/tmp/vagrant-chef-1/chef-solo-1/cookbooks/rbenv/providers/script.rb line 28)

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

Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '127'
---- Begin output of "bash"  "/tmp/chef-script20130405-18534-tu8l96-0" ----
STDOUT: 
STDERR: /tmp/chef-script20130405-18534-tu8l96-0: line 3: rbenv: command not found
/tmp/chef-script20130405-18534-tu8l96-0: line 5: rbenv: command not found
/tmp/chef-script20130405-18534-tu8l96-0: line 7: rbenv: command not found
---- End output of "bash"  "/tmp/chef-script20130405-18534-tu8l96-0" ----
Ran "bash"  "/tmp/chef-script20130405-18534-tu8l96-0" returned 127

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

 27: 
 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/vagrant-chef-1/chef-solo-1/cookbooks/rbenv/providers/script.rb:28:in `class_from_file'

script("rbenv install 1.9.3-p392 (vagrant)") do
  retry_delay 2
  environment {"RBENV_ROOT"=>"/home/vagrant/.rbenv", "HOME"=>"/home/vagrant", "USER"=>"vagrant"}
  user "vagrant"
  returns [0]
  command "\"bash\"  \"/tmp/chef-script20130405-18534-tu8l96-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-p392\n"
  action "run"
  cookbook_name :rails_env
  interpreter "bash"
  backup 5
end

[2013-04-05T19:37:26+00:00] ERROR: Running exception handlers
[2013-04-05T19:37:26+00:00] ERROR: Exception handlers complete
[2013-04-05T19:37:26+00:00] FATAL: Stacktrace dumped to /tmp/vagrant-chef-1/chef-stacktrace.out
[2013-04-05T19:37:26+00:00] FATAL: Mixlib::ShellOut::ShellCommandFailed: script[rbenv install 1.9.3-p392 (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-script20130405-18534-tu8l96-0" ----
STDOUT: 
STDERR: /tmp/chef-script20130405-18534-tu8l96-0: line 3: rbenv: command not found
/tmp/chef-script20130405-18534-tu8l96-0: line 5: rbenv: command not found
/tmp/chef-script20130405-18534-tu8l96-0: line 7: rbenv: command not found
---- End output of "bash"  "/tmp/chef-script20130405-18534-tu8l96-0" ----
Ran "bash"  "/tmp/chef-script20130405-18534-tu8l96-0" returned 127

@johnbellone
Copy link

@guidomb This is probably because you're not using a login shell for bash executions. Try it with bash -l and it'll source the /etc/profile.d/rbenv.sh script which throws everything into PATH.

@amccloud
Copy link

@johnbellone but his error is being caused by the rbenv_ruby resource. If bash -l is needed, then the rbenv_ruby resource needs to be updated.

@guidomb Did you ever end up solving this? My recipe essentially looks the same as yours.

@msaffitz
Copy link
Contributor Author

@fnichol can you take a look at this and merge if it looks like the right approach?

Merge current finchol into master
@fnichol
Copy link
Contributor

fnichol commented Mar 3, 2014

This would add the paths mentioned above into the Chef running process' $PATH environment variable, but keep in mind that ordering of resources would be important if you're counting on rbenv being loaded for shell out commands and the rbenv_script resource might be a better option to use which should properly load rbenv before executing the code.

fnichol added a commit that referenced this pull request Mar 3, 2014
Fix for #16, load rbenv environment after install
@fnichol fnichol merged commit 26f3265 into sous-chefs:master Mar 3, 2014
@lock
Copy link

lock bot commented May 31, 2018

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.

@lock lock bot locked as resolved and limited conversation to collaborators May 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Source rbenv.sh template after installing it
5 participants