nil:NilClass 的未定义方法 "cheffish",当使用 vagrant 供应厨师时

undefined method "cheffish" for nil:NilClass, when provisioning chef with vagrant

我正在尝试 运行 使用 Chef 的 Vagrant 盒子中的 django-server,但我已经坚持了几个小时,在网上找不到任何东西。我的 vagrantfile 的相关部分如下所示:(抱歉缩进不佳)此外,该框是 运行ning centos7.

config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "cookbooks"
chef.add_recipe "apache2"
chef.add_recipe "apt"
chef.add_recipe "bluepill"
chef.add_recipe "build-essential"
chef.add_recipe "chef-sugar"
chef.add_recipe "chef_handler"
chef.add_recipe "cms-scanner"
chef.add_recipe "gunicorn"
chef.add_recipe "homebrew"
chef.add_recipe "install_from"
chef.add_recipe "iptables"
chef.add_recipe "logrotate"
chef.add_recipe "metachef"
chef.add_recipe "mysql"
chef.add_recipe "nginx"
chef.add_recipe "ohai"
chef.add_recipe "openssl"
chef.add_recipe "packagecloud"
chef.add_recipe "pacman"
chef.add_recipe "python"
chef.add_recipe "rbac"
chef.add_recipe "redis"
chef.add_recipe "runit"
chef.add_recipe "smf"
chef.add_recipe "windows"
chef.add_recipe "yum"
chef.add_recipe "yum-epel"
end

当我 运行 vagrant provision

时出现此错误
 C:\Users\garrowa\Desktop\cms-vagrant>vagrant provision
    ==> default: Running provisioner: chef_solo...
    ==> default: Detected Chef (latest) is already installed
    Generating chef JSON and uploading...
    ==> default: Running chef-solo...
    ==> default: [2015-06-30T18:04:53-04:00] INFO: Forking chef instance to converge
    ...
    ==> default: [2015-06-30T18:04:53-04:00] INFO: *** Chef 12.4.0 ***
    ==> default: [2015-06-30T18:04:53-04:00] INFO: Chef-client pid: 4398
    ==> default: [2015-06-30T18:04:55-04:00] INFO: Setting the run_list to ["recipe[
    apache2]", "recipe[apt]", "recipe[bluepill]", "recipe[build-essential]", "recipe
    [chef-sugar]", "recipe[chef_handler]", "recipe[cms-scanner]", "recipe[gunicorn]"
    , "recipe[homebrew]", "recipe[install_from]", "recipe[iptables]", "recipe[logrot
    ate]", "recipe[metachef]", "recipe[mysql]", "recipe[nginx]", "recipe[ohai]", "re
    cipe[openssl]", "recipe[packagecloud]", "recipe[pacman]", "recipe[python]", "rec
    ipe[rbac]", "recipe[redis]", "recipe[runit]", "recipe[smf]", "recipe[windows]",
    "recipe[yum]", "recipe[yum-epel]"] from CLI options
    ==> default: [2015-06-30T18:04:55-04:00] INFO: Run List is [recipe[apache2], rec
    ipe[apt], recipe[bluepill], recipe[build-essential], recipe[chef-sugar], recipe[
    chef_handler], recipe[cms-scanner], recipe[gunicorn], recipe[homebrew], recipe[i
    nstall_from], recipe[iptables], recipe[logrotate], recipe[metachef], recipe[mysq
    l], recipe[nginx], recipe[ohai], recipe[openssl], recipe[packagecloud], recipe[p
    acman], recipe[python], recipe[rbac], recipe[redis], recipe[runit], recipe[smf],
     recipe[windows], recipe[yum], recipe[yum-epel]]
    ==> default: [2015-06-30T18:04:55-04:00] INFO: Run List expands to [apache2, apt
    , bluepill, build-essential, chef-sugar, chef_handler, cms-scanner, gunicorn, ho
    mebrew, install_from, iptables, logrotate, metachef, mysql, nginx, ohai, openssl
    , packagecloud, pacman, python, rbac, redis, runit, smf, windows, yum, yum-epel]

    ==> default: [2015-06-30T18:04:55-04:00] INFO: Starting Chef Run for localhost
    ==> default: [2015-06-30T18:04:55-04:00] INFO: Running start handlers
    ==> default: [2015-06-30T18:04:55-04:00] INFO: Start handlers complete.
    ==> default: [2015-06-30T18:04:55-04:00] ERROR: Running exception handlers
    ==> default: [2015-06-30T18:04:55-04:00] ERROR: Exception handlers complete
    ==> default: [2015-06-30T18:04:55-04:00] ERROR: undefined method `cheffish' for
    nil:NilClass
    ==> default: [2015-06-30T18:04:55-04:00] FATAL: Chef::Exceptions::ChildConvergeE
    rror: Chef run process exited unsuccessfully (exit code 1)
    Chef never successfully completed! Any errors should be visible in the
    output above. Please fix your recipes so that they properly complete.

真正让我感到困惑的是,我在这些食谱中的任何地方都找不到任何关于厨师鱼的参考资料。

我已经尝试删除除 ohai 之外的所有 chef.add_recipe 行,或者 yum,但我仍然遇到相同的错误。 (我在 运行ning vagrant reloadvagrant provision 之间尝试。我也尝试过 sshing 进入盒子,删除 cheffish gem, 运行ning vagrant provision,并重新安装 cheffish gem 和 运行ning vagrant provision,但无济于事。

终于明白了。正如评论中所指出的,这个问题是在 chef v. 12.4.0 中引入的,我将行 chef.version = "12.3.0" 添加到 provision 块中,现在它正在工作。

我在使用自定义食谱时遇到了完全相同的错误,并在该自定义食谱的食谱顶部调用了 include_recipe。 为我修复的是在自定义食谱中添加 metadata.rb。它应该包含 name 和 depends 部分。 希望这有帮助

如果您尝试在 metadata.rb 中使用 include_attribute 'foo' 而不是属性文件,就会发生这种情况。

对我来说,解决方案是确保我使用的每本食谱都有一个 "name" 属性,其中包含食谱的名称。 'redis'、'install_from' 和 'metachef' 食谱都缺少 metadata.rb

中的名称字段

chef-client v12.3.0 帮助发现了这一点,12.4.1 没有向我展示任何有用的东西

我的错误与两本自定义食谱有关,有人在 metadata.rb 更正它时修复了它。

不过,我在 Test Kitchen 中也遇到了同样的错误,但不是由该错误引起的。对于未满足食谱约束的一般情况(即无法找到的食谱名称或版本),错误消息异常神秘。在我的例子中,从 .kitchen.yml 开始,我包含了一个具有特定说明书版本约束的环境,然后在 Berksfile 中指定了冲突的版本约束。那太蠢了,所以不要那样做!

由于省略了食谱 metadata.rb 中的 name 得到了这个。添加 name 修复它。

我们看到的消息显然是 Chef 中的一个错误,希望很快得到修复,但与此同时,这也许可以帮助任何犯过与我相同错误的人。