RiotGamesCookbooks / rbenv-cookbook

Installs and configures rbenv
http://community.opscode.com/cookbooks/rbenv
Apache License 2.0
137 stars 109 forks source link

Installing new global ruby doesn't update current chef PATH #102

Closed irontoby closed 10 years ago

irontoby commented 10 years ago

I'm using rbenv to install a new global ruby in /opt/rbenv. Later in the same chef run, I'm compiling nginx from source. The newly-installed global ruby isn't found, I'm assuming because it wasn't in the PATH when the chef-run started.

I tried something like this after installing the rbenv ruby:

ruby_block 'set new rbenv ENV for chef run' do
  block { ENV['PATH'] = "/opt/rbenv/shims:/opt/rbenv/bin:#{ENV['PATH']}" }
  not_if { ENV['PATH'].include?('rbenv') }
end

but it apparently didn't run. So either my code block "did what it was supposed to" (i.e. the not_if block kept it from running), which leads me to believe a child process already set its PATH, but that change didn't stick around for my next recipe (which tried building nginx) -- or, my understanding of how chef works is lacking (probably that one).

So, is it possible to update the PATH of the current chef run (and any processes it fires off, such as building nginx), either from the rbenv recipe or my own recipe? Is this something the rbenv cookbook should do or is that considered bad practice?

irontoby commented 10 years ago

Ugh sorry for the noise, I see the actual problem... early in the chef run, I'm setting ['nginx']['passenger']['ruby'] using node['languages']['ruby']['ruby_bin'], so that's overriding the "which ruby" default. I need to set that value after reloading ohai, after installing the new rbenv.

So I'm guessing PATH actually was updated, so my not_if block kicked in. (And in actuality, it's only the passenger build that needs the current ruby, not nginx) If someone wants to clarify my understanding of this I'd appreciate it, but I'm closing the issue.