Skip to content

Instantly share code, notes, and snippets.

@icambron
Last active December 17, 2015 05:18
Show Gist options
  • Save icambron/5556420 to your computer and use it in GitHub Desktop.
Save icambron/5556420 to your computer and use it in GitHub Desktop.
Trying to use chef-rvm with vagrant

I'm trying to figure out why vagrant w/chef-solo + chef-rvm isn't working for me. Here's how I think it's supposed to work:

  1. You tell chef where chef-solo is installed on the vagrant image
  2. The rvm:vagrant recipe creates a wrapper script, also called chef-solo, that does this: a. set an environment variable overriding the current ruby to "system" b. calls chef-solo as specified in the attributes c. it goes on the path before the real chef-solo does
  3. the rvm:system recipe installs rvm and your specified ruby system-wide
  4. Now, the next time you do a vagrant up, chef-solo (which is now actually the wrapper script) will still work because it's using the system-installed ruby, which has access to the chef-solo gem, as opposed to your newly installed Ruby, which doesn't.

That all makes sense, except that I can't actually get it to work after the first time.

[app] Running provisioner: chef_solo...
Generating chef JSON and uploading...
Running chef-solo...
stdin: is not a tty
/usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
:
cannot load such file -- chef/application/solo
 (
LoadError
)
  from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
  from /usr/bin/chef-solo:22:in `<main>'
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.

In other words, it's not using the right ruby.

Here's my setup. From my Vagrantfile:

    chef.add_recipe "rvm::vagrant"
    chef.add_recipe "rvm::system"

    chef.json = {
      rvm: {
        rubies: ["1.9.3"],
        default_ruby: "1.9.3",
        vagrant: {
          system_chef_solo: "/usr/bin/chef-solo"
        }
      }
    }

That's definitely the path on my guest box, e.g.

application% head /usr/bin/chef-solo
#!/usr/bin/env ruby
#
# ./chef-solo - Run the chef client, in stand-alone mode
#
# Author:: AJ Christensen (<[email protected]>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");

Next, the wrapper does actually get created at /usr/local/bin/chef-solo:

#!/usr/bin/env bash

# RVM-aware chef-solo wrapper
#
# Generated by Chef for application
# Local modifications will be overridden

if [[ -d "/usr/local/rvm" ]] ; then
export PATH="/bin:/usr/local/rvm:$PATH"
  rvm_path='/usr/local/rvm'
  export rvm_path
  unset RUBY_VERSION
  unset GEM_HOME
  unset GEM_PATH
  unset MY_RUBY_HOME
  unset IRBRC
  rvm_ruby_string='system'
  export rvm_ruby_string
  unset rvm_gemset_name
  unset MAGLEV_HOME
fi

exec /usr/bin/chef-solo "$@"

Looks right to me. It is first on the path, so the wrapper should definitely be getting called:

application% which chef-solo
/usr/local/bin/chef-solo

And anyway, even running the wrapper manually doesn't work:

application% chef-solo
/usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- chef/application/solo (LoadError)
  from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
  from /usr/bin/chef-solo:22:in `<main>'

Though it does work if I switch RVM over:

application% rvm use system
Now using system ruby.
application% chef-solo
[2013-05-09T21:13:40+00:00] WARN: *****************************************
[2013-05-09T21:13:40+00:00] WARN: Did not find config file: /etc/chef/solo.rb, using command line options.
[2013-05-09T21:13:40+00:00] WARN: *****************************************
[2013-05-09T21:13:40+00:00] INFO: *** Chef 10.12.0 ***

So it's like it's ignoring the rvm variable in the wrapper? I'm stuck. Why isn't chef getting called by the system ruby?

@valzav
Copy link

valzav commented Oct 18, 2013

I had the same issue.
It should work if you replace "exec" with the following:
rvm-exec system /usr/bin/chef-solo "$@"

@MarkMurphy
Copy link

Same problem. @valzav 's solution solved it for me.

UPDATE

As it turns out, /usr/local/bin/chef-solo is overwritten every time you provision so the above solution would have to be applied to the chef-rvm wrapper template itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment