8

我正在尝试 vagrant install 并希望将其1.9.3-p327作为默认的 ruby​​ 版本。我正在使用 chef-solo 和 librarian-chef 来管理 vagrant 机器。

我为 chef-solo 配置的 vagrant 文件看起来像这样

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

图书馆员-厨师寻找的厨师文件看起来像这样

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'

从这两个中,我应该能够运行 vagrant 文件,不幸的是,它看起来好像我在哪里指定 ruby​​ 到 chef-solo 的版本正在轰炸。昨天下午还在工作,这让我觉得有人从那时到现在更新了一本食谱。所以当我打电话给图书管理员安装时,它把它拉了出来,吓坏了..

================================================================================
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.

如果我注释掉指定 ruby​​ 版本的 json,那么它就可以工作。似乎我必须指定 rbenv 的版本,但什么是受信任的版本,我在哪里可以找到它们。

编辑:您还必须在 json.xml 中指定用户详细信息。因为您安装到系统和用户(流浪者)级别。厨师正在使用 vagrant box 提供的红宝石。这是我为 rbenv json 更新的 ruby​​ 版本的样子。

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' }
          ]
        }
      }
    ]
  },
4

1 回答 1

7

这似乎是由于这本食谱使用的(坦率地说不寻常的)版本控制系统。他们的 master 分支不稳定,但是,如果您返回到最新的标记版本,错误就会消失。我使用 Berkshelf 而不是 librarian-chef,但语法看起来几乎相同,所以无论如何我都会包含我固定的 Berkshelf 行:

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

ref:是重要的一点。这为我解决了错误!

于 2013-06-08T22:14:11.997 回答