chef: knife cookbook site share doesn't work

I’m getting the error when trying to release a new version for the aegir3 cookbook (https://github.com/daften/cookbook-aegir3):

ERROR: knife encountered an unexpected error
This may be a bug in the 'cookbook site share' knife command or plugin
Please collect the output of this command with the `-VV` option before filing a bug report.
Exception: NameError: undefined local variable or method `method_name' for Chef::Cookbook::Metadata:Class

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 18 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Awesome! if anyone needs to manually patch that commit will likely work, and it’s super simple.

We’re discussing a more complete patch here: https://github.com/chef/chef/pull/4428

I ran into this while trying to share a cookbook with only metadata.rb, however it was managed by Berkshelf, and was first:

  • installed from GitHub source with berks install
  • Uploaded to hosted Chef with berks upload
  • Vendored into a Chef Repo (e.g: ~/src/pub/chef-repo/cookbooks) with berks vendor cookbooks/
  • Shared to Supermarket with knife cookbook site share my-cookbook "Applications" -o cookbooks

Due to the back & forth from Chef Server with berks upload & berks vendor, the metadata.rb gets converted into metadata.json. Thus, knife cookbook site share my-cookbook "Applications" -o cookbooks -VV returned an error:

INFO: Using configuration from /home/trinitronx/.chef/knife.rb
DEBUG: No chefignore file found at /home/trinitronx/src/pub/chef-repo/chefignore no files will be ignored
DEBUG: No chefignore file found at cookbooks/site-cookbooks/chefignore no files will be ignored
INFO: Validating ruby files
INFO: Validating templates
INFO: Syntax OK
DEBUG: Staging at /tmp/chef-my-cookbook-build20160118-18240-mu1l3x
DEBUG: Staging /home/trinitronx/src/pub/chef-repo/cookbooks/my-cookbook/recipes/default.rb to /tmp/chef-my-cookbook-build20160118-18240-mu1l3x/my-cookbook/recipes/default.rb
DEBUG: Staging /home/trinitronx/src/pub/chef-repo/cookbooks/my-cookbook/attributes/default.rb to /tmp/chef-my-cookbook-build20160118-18240-mu1l3x/my-cookbook/attributes/default.rb
DEBUG: Staging /home/trinitronx/src/pub/chef-repo/cookbooks/my-cookbook/chefignore to /tmp/chef-my-cookbook-build20160118-18240-mu1l3x/my-cookbook/chefignore
DEBUG: Staging /home/trinitronx/src/pub/chef-repo/cookbooks/my-cookbook/README.md to /tmp/chef-my-cookbook-build20160118-18240-mu1l3x/my-cookbook/README.md
DEBUG: Staging /home/trinitronx/src/pub/chef-repo/cookbooks/my-cookbook/Rakefile to /tmp/chef-my-cookbook-build20160118-18240-mu1l3x/my-cookbook/Rakefile
DEBUG: Staging /home/trinitronx/src/pub/chef-repo/cookbooks/my-cookbook/metadata.json to /tmp/chef-my-cookbook-build20160118-18240-mu1l3x/my-cookbook/metadata.json
DEBUG: Staging /home/trinitronx/src/pub/chef-repo/cookbooks/my-cookbook/Gemfile to /tmp/chef-my-cookbook-build20160118-18240-mu1l3x/my-cookbook/Gemfile
DEBUG: Generating metadata
ERROR: knife encountered an unexpected error
This may be a bug in the 'cookbook site share' knife command or plugin
Please collect the output of this command with the `-VV` option before filing a bug report.
Exception: NameError: undefined local variable or method `method_name' for Chef::Cookbook::Metadata:Class

After manually applying @andy-dufour’s patch above to my ChefDK install at: /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.5.1/lib/chef/cookbook/metadata.rb, I re-ran knife cookbook site share my-cookbook "Applications" -o cookbooks and it worked!

So, this patch worked for me: https://github.com/chef/chef/commit/3d769be3383f7f73c3ee6ed7bce75e40f2ae56c6