1
votes

I have this problem with Vagrant and chef. I got already prepared Vagrantfile and chef cookbooks to use. Basically the vagrantfile is configured by some env variables, so I'm able to create new virtual machine from the Vagrantfile and also all configuration and provisioning is done by chef, but once the virtual machine is finished, chef is not working.

When I execute "vagrant provision" I get this error message:

/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find chef (>= 0) amongst [bigdecimal-1.1.0, io-console-0.3, json-1.5.4, minitest-2.5.1, rake-0.9.2.2, rdoc-3.9.4] (Gem::LoadError)

I can't change versions too much, to not break something...As you can see from the error message, there is rvm (1.15.8). Ruby in version 1.9.3 and chef in version 10.12.0.

Before the chef is working for sure, because I was able to create the virtual machine... But then something changed and I can't find out what...I'm going back and forth through all the chef roles/cookbooks/recipes but I can't figure out :(

The RVM is installed for all users, so the /etc/profile.d/rvm.sh is used for the env setup.

Maybe some hints from you could help me, thank you!

3
I once had a similar issue : the chef gem was already present on the machine ( /opt/vagrant-ruby/bin or something like that ), but when installing rvm it was not present in the PATH anymore. I however didn't actually solve this issue, and chose to instal ruby from source without rvm instead...MrRuru
Thanks for comment, I'm checking PATH variable now and it seems that there could be the problem...not sure yet, but at least something. I was little bit out of ideas..stibi
fnichol.github.io/chef-rvm apparently defines a custom recipe for accessing the chef-solo binaries in a Vagrant VM. Didn't try it thoughMrRuru
Use the vagrant omnibus plugin and this will install the specified version of chef complete with it's own distribution of ruby. Much better way to ensure consistency. See github.com/schisamo/vagrant-omnibusMark O'Connor
Did you find a solution to this problem? It's okay to answer your own question. Please don't forget to mark an answer as correct! :)sethvargo

3 Answers

0
votes

You need to include vagrant recipe. It does two things: adds vagrant user to the rvm group and installs a chef-solo/chef-client wrapper scripts.

Remember to point wrappers to the correct binaries (depending on where system rubies is located) using node['rvm']['vagrant']['system_chef_solo'] and node['rvm']['vagrant']['system_chef_client'] attributes.

Example for chef-solo:

chef.add_recipe "rvm::vagrant"

chef.json = {
  :rvm => {
    :vagrant => {
      :system_chef_solo => '/usr/lib/ruby/gems/1.8/gems/chef-11.4.0/bin/chef-solo',
      :system_chef_client => '/usr/lib/ruby/gems/1.8/gems/chef-11.4.0/bin/chef-client'
    }
  }
}

In addition, you have two other options:

0
votes

Since your chef run installs rvm and rubies, you must change how chef-solo is being executed to have a prefix of rvm system do chef-solo. This will ensure that rvm gets out of his way from the Chef OmniBus ruby, or whatever other ruby it wants/needs to use.

In my vagrantfile, I use shell provisioner to run chef-solo like this:

# with rvm installed, chef will not work with its ruby. must use system!
[ -f /usr/local/rvm/bin/rvm ] && pfx="rvm system do"

$pfx chef-solo -c /vagrant/chef-solo.rb -j /vagrant/chef-solo.js --no-fork
0
votes

I included the Vagrant recipe as well, but that didn't completely solve the problem.

I added the following as attributes in my recipe:

default.rvm.vagrant.system_chef_client = "/usr/bin/chef-client"
default.rvm.vagrant.system_chef_solo = "/usr/bin/chef-solo"

since my default chef-client and chef-solo executables were in /usr/bin

The RVM Vagrant recipe adds a couple of wrapper scripts into the /usr/local/bin directory. When I tried running rvm provision after already provisioning the server once, it looked like it was completely ignoring the chef-client and chef-solo executables in /usr/local/bin.

To get around this, I also added the following into my Vagrantfile, which explicitly set the $PATH to look into /usr/local/bin first:

chef.binary_env="PATH=/usr/local/bin:/usr/bin:/usr/sbin:/bin"