ruby - 在 vagrant rbenv NoMethodError loaded_recipe 上安装 ruby​​ 1.9.3?

标签 ruby vagrant rbenv

我正在尝试 vagrant 安装并希望将 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

librarian-cheff 查找的 cheffile 看起来像这样

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 文件,不幸的是,它看起来好像我正在为 chef-solo 指定 ruby​​ 版本的地方被炸毁了。它昨天下午还在工作,这让我认为从那时到现在有人更新了一本食谱。所以当我调用 librarian-chef install 时,它把它拉了下来,吓坏了..

================================================================================
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 中指定用户详细信息。自从您安装到系统和用户( Vagrant )级别。厨师正在使用 vagrant box 提供的 ruby 。这是我为 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' }
          ]
        }
      }
    ]
  },

最佳答案

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

食谱“rbenv”,git:“git://github.com/fnichol/chef-rbenv.git”,引用:“v0.7.2”

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

关于ruby - 在 vagrant rbenv NoMethodError loaded_recipe 上安装 ruby​​ 1.9.3?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16855064/

相关文章:

ruby - 在 Mac OS 上安装 rbenv 后如何解决消息 "No such file or directory"?

ruby-on-rails - 跟踪医生、客户和预约的变化 :)

ruby-on-rails - 如何将哈希中的 "dot-notation"字符串键转换为嵌套哈希?

ruby-on-rails - Rails 授权查询不起作用

php - 如何在 PhpStorm 中为在 Vagrant 中运行的 Laravel Web 应用程序正确设置 XDebug? (Mac 操作系统)

ruby - 如何使用 Aptana Studio 3 和 rbenv 调试 Ruby 脚本?

ruby-on-rails - 如何使用Rails连接到PostgreSQL容器

php - 在 PHPStorm 中将一个目录路径映射到另一个目录路径

ubuntu-12.04 - Vagrant up 在 "Waiting for machine to boot. This may take a few minutes..."完成启动后需要很长时间

使用 rbenv 成功安装 Ruby,但无法访问