1
votes

I'm using chef-solo to provision a new vagrant VM. It's Ubuntu 12.10. Chef runs fine the first time, but fails to launch anytime thereafter.

The problem is that chef-solo needs to run using ruby 1.9.3, but one of my cookbooks installs ruby 2.0.0. It links the new version of ruby to /usr/local/ruby, so the system version is still available at /usr/bin/ruby.

The shebang line in /usr/bin/chef-solo is #!/usr/bin/env ruby.

Is there a way I can set an environment variable in the Vagrantfile before chef-solo runs? Or is there another way to force vagrant to run chef-solo using /usr/bin/ruby?

UPDATE: I'm currently using the following command on the VM as a work-around:

sudo /usr/bin/ruby /usr/bin/chef-solo --config /tmp/vagrant-chef-1/solo.rb --override-runlist "my_runlist"

I'd like to force Vagrant to run something similar when I type vagrant provision on the host.

2
chef-solo runs in your VM - do you want to control which Ruby version is used there or on your host maschine?cmur2
On the VM. I added a clarification/workaround to the question above.AndrewF

2 Answers

1
votes

/usr/bin/env works by using $PATH to find the executable. You should make sure that /usr/bin/ruby is at the front of your path. One way to ensure this is:

export PATH=/usr/bin:$PATH

..and then try your chef-solo run.

Here's more from: http://en.wikipedia.org/wiki/Shebang_(Unix)#Portability

Often, the program /usr/bin/env can be used to circumvent this limitation by introducing a level of indirection. #! is followed by /usr/bin/env, followed by the desired command without full path, as in this example:

!/usr/bin/env sh

This mostly works because the path /usr/bin/env is commonly used for the env utility, and it invokes the first sh found in the user's $PATH, typically /bin/sh, if the user's path is correctly configured.

1
votes

Using the vagrant omnibus plugin you can install Chef Omnibus which has its own embedded Ruby, to guarantee that Chef runs always use the same Ruby version.

The only issue I found with this is that if your recipes rely on the system version of ruby some setups won't work correctly (for instance, a ruby installed in /usr/local/bin won't be use if you shell_out! in a cookbook, but an intallation in /usr/bin will).