How to solve knife (chef) error Exception: NoMethodError

Written by - 0 comments

Published on - Listed in Linux


Since a recent update of some installed packages, my chef command 'knife' suddenly didn't work anymore:

knife status
ERROR: knife encountered an unexpected error
This may be a bug in the 'status' knife command or plugin
Please collect the output of this command with the `-VV` option before filing a bug report.
Exception: NoMethodError: undefined method `name' for #<Hash:0x00000002893508>

So I launched knife again, as mentioned, with the -VV option:

knife status -VV
DEBUG: Using configuration from /home/ckuenzler/.chef/knife.rb
DEBUG: Signing the request as xxx
DEBUG: Sending HTTP Request via GET to chef.exmample.com:443/search/node
DEBUG: ---- HTTP Status and Header Data: ----
DEBUG: HTTP 1.1 200 OK
DEBUG: server: nginx/1.1.19
DEBUG: date: Fri, 03 May 2013 11:10:53 GMT
DEBUG: content-type: application/json; charset=utf-8
DEBUG: transfer-encoding: chunked
DEBUG: connection: close
DEBUG: ---- End HTTP Status/Header Data ----
/usr/lib64/ruby/gems/1.9.1/gems/chef-10.16.2/lib/chef/knife/status.rb:88:in `block in run': undefined method `name' for #<Hash:0x00000001296fe8> (NoMethodError)
        from /usr/lib64/ruby/gems/1.9.1/gems/chef-10.16.2/lib/chef/knife/status.rb:58:in `each'
        from /usr/lib64/ruby/gems/1.9.1/gems/chef-10.16.2/lib/chef/knife/status.rb:58:in `run'
        from /usr/lib64/ruby/gems/1.9.1/gems/chef-10.16.2/lib/chef/knife.rb:408:in `run_with_pretty_exceptions'
        from /usr/lib64/ruby/gems/1.9.1/gems/chef-10.16.2/lib/chef/knife.rb:168:in `run'
        from /usr/lib64/ruby/gems/1.9.1/gems/chef-10.16.2/lib/chef/application/knife.rb:123:in `run'
        from /usr/lib64/ruby/gems/1.9.1/gems/chef-10.16.2/bin/knife:25:in `<top (required)>'
        from /usr/bin/knife:23:in `load'
        from /usr/bin/knife:23:in `<main>'

Well that does not tell me the exact reason of the problem, but my guess is, that ruby itself was updated during the latest package patching, but the gem files still staid the same. So the newer ruby would probably run into issues with the old gems.

To solve this, the gems have to be redownloaded and reinstalled (as root):

gem install knife-block --no-rdoc --no-ri
gem install knife-audit --no-rdoc --no-ri
gem install knife-preflight --no-rdoc --no-ri
gem install knife-essentials --no-rdoc --no-ri
gem install knife-env-diff --no-rdoc --no-ri
gem install knife-flip --no-rdoc --no-ri
gem install chef --no-rdoc --no-ri

Afterwards, the knife command worked again:

knife status -VV
DEBUG: Signing the request as xxx
DEBUG: Sending HTTP Request via GET to chef.example.com:443/search/node
DEBUG: ---- HTTP Status and Header Data: ----
DEBUG: HTTP 1.1 200 OK
DEBUG: server: nginx/1.1.19
DEBUG: date: Fri, 03 May 2013 11:13:00 GMT
DEBUG: content-type: application/json; charset=utf-8
DEBUG: transfer-encoding: chunked
DEBUG: connection: close
DEBUG: ---- End HTTP Status/Header Data ----
2 minutes ago, linux15, linux15.example.com, 10.0.34.15, centos 6.3.


Add a comment

Show form to leave a comment

Comments (newest first)

No comments yet.