undefined method “cheffish” for nil:NilClass, when

2019-02-09 03:22发布

问题:

I'm trying to run a django-server in a Vagrant box using Chef, but I've been stuck on this for a few hours and can't find anything online. The relevant bit of my vagrantfile looks like this: (sorry for the poor indentation) Also, the box is running 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

And I get this error when I run 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.

What really confuses me is that I can't find any references to cheffish anywhere in any of these cookbooks.

I've tried eliminating all chef.add_recipe lines except ohai, and alternatively yum, but I still get the same error. (I am running vagrant reload and vagrant provision between tries. I've also tried sshing into the box, removing the cheffish gem, running vagrant provision, and reinstalling the cheffish gem and running vagrant provision, but to no avail.

回答1:

Finally got it. As pointed out in the comments this problem is introduced in chef v. 12.4.0, I added the line chef.version = "12.3.0" to the provision block and now it's working.



回答2:

for me the solution was to make sure every cookbook I was using had a "name" attribute in it with the name of the cookbook. 'redis', 'install_from', and 'metachef' cookbooks were all missing the name field from the metadata.rb

chef-client v12.3.0 helped uncover this, 12.4.1 was not showing me anything useful



回答3:

The error for me was related to two custom cookbooks that someone how had the same name in metadata.rb correcting it fixed it.



回答4:

I had exactly the same error when using a custom cookbook with a include_recipe call at the top of a recipe in that custom cookbook. What fixed it for me is adding a metadata.rb to the custom cookbook. It should contain name and depends sections. Hope this helps



回答5:

It happens if you try to use include_attribute 'foo' in metadata.rb instead of attributes file.



回答6:

I've gotten this same error in Test Kitchen as well, though, not caused by the bug. The error message is exceptionally cryptic for the general case of a cookbook constraint not being met (i.e. a cookbook name or version that can't be found). In my case, from .kitchen.yml, I included an environment with specific cookbook version constraints, then specified conflicting version constraints in a Berksfile. That was dumb, so don't do that!



回答7:

Got this due to omitting the name from a cookbook's metadata.rb. Adding the name fixed it.

The message we're seeing is clearly a bug in Chef and hopefully will get fixed soon, but in the meantime perhaps this can help anybody who made the same mistake as me.



标签: vagrant chef