Recipes that alter PATH


#1

Hello,

I have a recipe that installs rvm and Ruby Enterprise Edition via rvm. Once
that recipe runs, I have subsequent recipes that run and install gems. The
problem is that they install the gems in system Ruby.

For rvm to work, I need to source a shell script (which I do in
/etc/profile.d/rvm.sh). The problem is that subsequent calls to Chef
resources like “execute”, “gem_package” or “script” don’t
run /etc/profile.d/rvm.sh before executing. How can I remedy that?

Thanks for the help.


#2

This is commonly solved with the ‘reboot’ cookbook, to restart the Chef run
mid to inherit the new environment.

Regards,

AJ

On 8 Jul 2010 05:35, “Christopher Bottaro” cjbottaro@onespot.com wrote:

Hello,

I have a recipe that installs rvm and Ruby Enterprise Edition via rvm.
Once
that recipe runs, I have subsequent recipes that run and install gems. The
problem is that they install the gems in system Ruby.

For rvm to work, I need to source a shell script (which I do in
/etc/profile.d/rvm.sh). The problem is that subsequent calls to Chef
resources like “execute”, “gem_package” or “script” don’t
run /etc/profile.d/rvm.sh before executing. How can I remedy that?

Thanks for the help.


#3

On Wed, Jul 7, 2010 at 10:35 AM, Christopher Bottaro
cjbottaro@onespot.com wrote:

Hello,
I have a recipe that installs rvm and Ruby Enterprise Edition via rvm. Once
that recipe runs, I have subsequent recipes that run and install gems. The
problem is that they install the gems in system Ruby.
For rvm to work, I need to source a shell script (which I do in
/etc/profile.d/rvm.sh). The problem is that subsequent calls to Chef
resources like “execute”, “gem_package” or “script” don’t
run /etc/profile.d/rvm.sh before executing. How can I remedy that?
Thanks for the help.

The trick is to run the RVM command, then evaluate the environment in
the sub-shell and set the current running environment to match.

Best,
Adam


Opscode, Inc.
Adam Jacob, CTO
T: (206) 508-7449 E: adam@opscode.com


#4

Pretty nifty trick! Unfortunately it doesn’t work for me. Every subsequent
use of the “bash” resource errors with “No such file or directory - bash
/tmp/chef-script.1990.0”. I printed out my ENV[“PATH”] after your
ruby_block trick and it looks correct.

I’m using Chef 0.7.16.

Does the reboot cookbook require a certain version of Chef?

Thanks for the help.

On Wed, Jul 7, 2010 at 6:44 PM, Adam Jacob adam@opscode.com wrote:

On Wed, Jul 7, 2010 at 10:35 AM, Christopher Bottaro
cjbottaro@onespot.com wrote:

Hello,
I have a recipe that installs rvm and Ruby Enterprise Edition via rvm.
Once
that recipe runs, I have subsequent recipes that run and install gems.
The
problem is that they install the gems in system Ruby.
For rvm to work, I need to source a shell script (which I do in
/etc/profile.d/rvm.sh). The problem is that subsequent calls to Chef
resources like “execute”, “gem_package” or “script” don’t
run /etc/profile.d/rvm.sh before executing. How can I remedy that?
Thanks for the help.

http://gist.github.com/336957

The trick is to run the RVM command, then evaluate the environment in
the sub-shell and set the current running environment to match.

Best,
Adam


Opscode, Inc.
Adam Jacob, CTO
T: (206) 508-7449 E: adam@opscode.com