chef cookbook fails on ohai undefined method `[]' for nil:NilClass chef cookbook fails on ohai undefined method `[]' for nil:NilClass nginx nginx

chef cookbook fails on ohai undefined method `[]' for nil:NilClass


You haven't stated which version of the ohai and nginx cookbooks you're using.

While I can't answer your question I can provide some advice on managing your cookbooks by using a dependency manager (think bundler for cookbooks).

Install Berkshelf

gem install berkshelf

Create a Berkshelf file

$ cat Berksfilesite :opscodecookbook "nginx"

And use this to download all the cookbooks associated with nginx:

$ berks install -p cookbooksUsing nginx (2.0.0)Using apt (2.3.0)Using bluepill (2.3.0)Using rsyslog (1.9.0)Using build-essential (1.4.2)Using ohai (1.1.12)Using runit (1.2.0)Using yum (2.3.2)

The "-p" option places them in the "cookbooks" subdirectory:

$ ls -d cookbooks/*cookbooks/apt       cookbooks/build-essential  cookbooks/ohai     cookbooks/runitcookbooks/bluepill  cookbooks/nginx            cookbooks/rsyslog  cookbooks/yum


I have experienced the same error. You may find 3 other solutions to this problem, and an explanation why it's happening here on stackoverflow.

To mention one for those using Vagrant: Just include the recipe through Vagrantfile "chef.add_recipe()".

Using Berkshelf is obviously solving the issue, and I honestly like it. Just think that we should save the time of those who doesn't want to bother with installing new tools.


Ran into this trying to use community nexus cookbook. Solved it by specifying latest version of nginx cookbook in my metadata.rb:depends 'nginx', '>= 2.7.6'

The nexus cookbook metadata.rb specifies:depends "nginx", ">= 1.8.0"

So seems that chef will choose 1.8.0 when resolving deps unless you specify a newer version.