Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing ruby 1.9.3 on vagrant rbenv NoMethodError loaded_recipe?

i am attempting an vagrant install and would like to have 1.9.3-p327 as the default ruby version. i am using chef-solo and librarian-chef to manage the vagrant machine.

my vagrant file provisioning for chef-solo looks like this

config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "cookbooks"
chef.add_recipe "apt"
chef.add_recipe "build-essential"
chef.add_recipe "git"
chef.add_recipe "ruby_build"
chef.add_recipe "rbenv::system"
chef.add_recipe "rbenv::vagrant"
chef.add_recipe "sqlite"
chef.add_recipe "nodejs"
chef.add_recipe "mysql"
chef.add_recipe "redisio"
chef.add_recipe "redisio::install"
chef.add_recipe "redisio::redis_gem"
chef.add_recipe "zlib"
chef.add_recipe "wkhtmltopdf"

chef.json = { 
  "rbenv" => {
    "rubies" => [ "1.9.3-p327" ],
    "global" => "1.9.3-p327",
    "gems" => {
      "1.9.3-p327" => [
        { "name" => "bundler" }
      ]
    }
  }
}
end

and the cheffile that librarian-cheff looks for looks like this

site 'http://community.opscode.com/api/v1'

cookbook 'apt'
cookbook 'git'
cookbook 'build-essential'
cookbook 'rbenv',
  git: 'https://github.com/fnichol/chef-rbenv.git'
cookbook 'ruby_build'
cookbook 'sqlite',
  git: 'git://github.com/opscode-cookbooks/sqlite.git'
cookbook 'nodejs',
  git: 'http://github.com/mdxp/nodejs-cookbook'
cookbook 'mysql',
  git: 'git://github.com/opscode-cookbooks/mysql.git'
cookbook 'redisio',
  git: 'git://github.com/brianbianco/redisio.git'
cookbook 'zlib',
  git: 'git://github.com/opscode-cookbooks/zlib'
cookbook 'wkhtmltopdf',
  git: 'git://github.com/firstbanco/chef-wkhtmltopdf.git'

and from these two i should be able to run the vagrant file unfortunately it looks as if where i am specifying the version of ruby to chef-solo is bombing out. it was working yesterday afternoon which leads me to think that someone has updated a cookbook between then and now. so when i called librarian-chef install it pulled it and has freaked out..

================================================================================
Error executing action `install` on resource 'rbenv_ruby[1.9.3-p327] (system)'
================================================================================

NoMethodError
-------------
undefined method `loaded_recipe?' for #<Chef::RunContext:0x7f34cf773ed0>

Cookbook Trace:
---------------

/tmp/vagrant-chef-1/chef-solo-1/cookbooks/rbenv/providers/ruby.rb:88:in `ruby_build_missing?'
/tmp/vagrant-chef-1/chef-solo-1/cookbooks/rbenv/providers/ruby.rb:43:in `perform_install'
/tmp/vagrant-chef-1/chef-solo-1/cookbooks/rbenv/providers/ruby.rb:33:in `class_from_file'

Resource Declaration:
---------------------
# In /tmp/vagrant-chef-1/chef-solo-1/cookbooks/rbenv/recipes/system.rb

 27:   else
 28:     rbenv_ruby rubie
 29:   end

 Compiled Resource: 
------------------
# Declared in /tmp/vagrant-chef-1/chef-solo-1/cookbooks/rbenv/recipes/system.rb:28:in `from_file'

rbenv_ruby("1.9.3-p327") do
  retry_delay 2
  retries 0
  recipe_name "system"
  definition "1.9.3-p327"
  action :install
  cookbook_name :rbenv
end

[2013-05-31T09:55:55+00:00] ERROR: Running exception handlers
[2013-05-31T09:55:55+00:00] ERROR: Exception handlers complete
[2013-05-31T09:55:55+00:00] FATAL: Stacktrace dumped to /tmp/vagrant-chef-1/chef-stacktrace.out
[2013-05-31T09:55:55+00:00] FATAL: NoMethodError: rbenv_ruby[1.9.3-p327] (system) (rbenv::system line 28) had an error: NoMethodError: undefined method `loaded_recipe?' for #<Chef::RunContext:0x7f34cf773ed0>
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.

if i comment out the json that specifies the ruby version then it works. it seems as if ill have to specify versions of rbenv but what are trusted versions and where can i find them.

Edit: you will also have to specify the user details in the json. since your installing to system and user(vagrant) levels. and chef is using the ruby that the vagrant box provides. here is what my updated ruby version for rbenv json looks like.

chef.json = {
  'rbenv' => {
    'user_installs' => [
      {
        'user'    => 'vagrant',
        'rubies'  => ['1.9.3-p327'],
        'global'  => '1.9.3-p327',
        'gems'    => {
          '1.9.3-p327' => [
            { 'name'    => 'bundler' },
            { 'name'    => 'rake' }
          ]
        }
      }
    ]
  },
like image 890
TheLegend Avatar asked May 31 '13 10:05

TheLegend


1 Answers

This appears to be due to the (frankly unusual) versioning system this cookbook is using. Their master branch is not stable, however, if you go back to the most recent tagged version, the error goes away. I use Berkshelf rather than librarian-chef but the syntax looks almost identical so I shall include my fixed Berkshelf line anyway:

cookbook 'rbenv', git: 'git://github.com/fnichol/chef-rbenv.git', ref: "v0.7.2"

The ref: is the important bit. This fixed the error for me!

like image 189
Bessey Avatar answered Nov 18 '22 14:11

Bessey