How to resolve “NoMethodError” in Chef

Recently I was given a task to implement Chef on clients infrastructure. What I have learned along the way is that when deploying Chef on existing server infrastructure, there will be almost no two identical systems and that each server node is different. You have to be extra careful when provisioning servers, especially production ones. Sometimes you even stumble upon errors in Chef itself. I have discovered one such error recently and I’m going to tell you a simple solution for solving it.

If you ever encountered error like this:


================================================================================
Error Syncing Cookbooks:
================================================================================

Unexpected Error:
-----------------
NoMethodError: undefined method `close!' for nil:NilClass

you may wonder what this error means, especially if you are not a software developer. Luckily you can run chef-client client in debug mode like this:

chef-client -l debug

If you know Ruby, you’ll probably spot a traceback, but you’ll have to dig deeper into it only to find, that one of the libraries in Chef (fileĀ http.rb on line 368) has a broken exception handling. When there is a temporary file creation problem, the traceback fires, but instead giving you a proper Exception, it will raise error like the one on top of this post. Changing line:

tr.close!

to:

tr.close! if tr

resolves the problem with Exception and gives us a proper error:


================================================================================
Error Syncing Cookbooks:
================================================================================

Unexpected Error:
-----------------
ArgumentError: could not find a temporary directory

This is way easier to solve than the previous error, because it simply means that the temporary directory (usually /tmp) has improper permissions.

You should do:

chmod o+t /tmp

and voila! The problem is solved. You can now run chef-client again and the cookbooks will be synced.

About Wolverine

If you are looking for IT consultant, let me know! karol at karoltomala dot REMOVE com Just remove the REMOVE word from the e-mail above!
This entry was posted in Chef and tagged , , , , . Bookmark the permalink.

One Response to How to resolve “NoMethodError” in Chef

  1. Todd Lyons says:

    You can also get the exact same “Error Syncing Cookbooks:” that you pasted above if you fill up the partition that chef-client uses to download cookbooks (/var/chef by default).

Leave a Reply

Your email address will not be published. Required fields are marked *