fnichol/chef-rvm — Issue #69: rvm_shell not setting environment variables on system install
Author: cswilliams
Created: 2012-01-26 09:26:02+00:00
State: open

Hi,

I am using the system based install and no individual user rvm. I am trying to run a command that depends on the correct HOME environment variable being set as the user running the command. However, I am finding $HOME is set to the home of the user running the chef-client command. For example:

rvm_shell "a command" do
code "echo $HOME > /tmp/env.txt"
user "chris"
end

then suppose I start my chef-client run with rvmsudo as user "ubuntu"

this command will output with the text "/home/ubuntu", when I would expect it to be "/home/chris".

So I dug into the code and modified providers/shell.rb and changed lines 80-85 to:
if new_resource.user && new_resource.environment
environment({ 'USER' => new_resource.user, 'HOME' => user_home }.merge(
new_resource.environment))
elsif new_resource.user
environment({ 'USER' => new_resource.user, 'HOME' => user_home })
end

Anyhow, I'm not sure if that is the correct fix, but it did the trick for me.

-Chris