厨师食谱在nil:NilClass的ohai未定义方法`[]'上失败 [英] chef cookbook fails on ohai undefined method `[]' for nil:NilClass

查看:88
本文介绍了厨师食谱在nil:NilClass的ohai未定义方法`[]'上失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一本厨师食谱,以在我无业游民的盒子上设置带有nginx postgresql和unicorn的香草ubuntu 12.04.2,但是我遇到了有关nginx的麻烦,有一个例外

I'm working on a chef cookbook to set up a vanilla ubuntu 12.04.2 with nginx postgresql and unicorn on my vagrant box, but I'm getting into troubles with nginx, there's an exception

undefined method `[]' for nil:NilClass

在安装时似乎与ohai配置有关.

when installing it that seem to relate to ohai configuration.

我已经在这里发布了所有内容:

I've posted all I have here:

https://github.com/DonGiulio/mychef

这是Chef-solo的输出:

here's the output from chef-solo:

Starting Chef Client, version 11.4.0
Compiling Cookbooks...

================================================================================
Recipe Compile Error in /var/chef/cookbooks/nginx/recipes/source.rb
================================================================================


NoMethodError
-------------
undefined method `[]' for nil:NilClass


Cookbook Trace:
---------------
  /var/chef/cookbooks/nginx/recipes/ohai_plugin.rb:27:in `from_file'
  /var/chef/cookbooks/nginx/recipes/source.rb:42:in `from_file'


Relevant File Content:
----------------------
/var/chef/cookbooks/nginx/recipes/ohai_plugin.rb:

 20:  #
 21:  
 22:  ohai 'reload_nginx' do
 23:    plugin 'nginx'
 24:    action :nothing
 25:  end
 26:  
 27>> template "#{node['ohai']['plugin_path']}/nginx.rb" do
 28:    source 'plugins/nginx.rb.erb'
 29:    owner  'root'
 30:    group  'root'
 31:    mode   '0755'
 32:    notifies :reload, 'ohai[reload_nginx]', :immediately
 33:  end
 34:  
 35:  include_recipe 'ohai::default'
 36:  


[2013-11-19T14:22:23+00:00] ERROR: Running exception handlers
[2013-11-19T14:22:23+00:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated
[2013-11-19T14:22:23+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2013-11-19T14:22:23+00:00] FATAL: NoMethodError: undefined method `[]' for nil:NilClass

这是堆栈跟踪:

$ cat /var/chef/cache/chef-stacktrace.out
Generated at 2013-11-19 14:22:23 +0000
NoMethodError: undefined method `[]' for nil:NilClass
/var/chef/cookbooks/nginx/recipes/ohai_plugin.rb:27:in `from_file'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.0/lib/chef/mixin/from_file.rb:30:in `instance_eval'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.0/lib/chef/mixin/from_file.rb:30:in `from_file'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.0/lib/chef/cookbook_version.rb:346:in `load_recipe'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.0/lib/chef/run_context.rb:151:in `load_recipe'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.0/lib/chef/run_context.rb:132:in `block in include_recipe'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.0/lib/chef/run_context.rb:131:in `each'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.0/lib/chef/run_context.rb:131:in `include_recipe'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.0/lib/chef/dsl/include_recipe.rb:26:in `include_recipe'
/var/chef/cookbooks/nginx/recipes/source.rb:42:in `from_file'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.0/lib/chef/mixin/from_file.rb:30:in `instance_eval'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.0/lib/chef/mixin/from_file.rb:30:in `from_file'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.0/lib/chef/cookbook_version.rb:346:in `load_recipe'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.0/lib/chef/run_context.rb:151:in `load_recipe'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.0/lib/chef/run_context/cookbook_compiler.rb:139:in `block in compile_recipes'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.0/lib/chef/run_context/cookbook_compiler.rb:137:in `each'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.0/lib/chef/run_context/cookbook_compiler.rb:137:in `compile_recipes'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.0/lib/chef/run_context/cookbook_compiler.rb:74:in `compile'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.0/lib/chef/run_context.rb:86:in `load'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.0/lib/chef/client.rb:224:in `setup_run_context'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.0/lib/chef/client.rb:467:in `do_run'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.0/lib/chef/client.rb:200:in `run'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.0/lib/chef/application.rb:190:in `run_chef_client'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.0/lib/chef/application/solo.rb:239:in `block in run_application'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.0/lib/chef/application/solo.rb:231:in `loop'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.0/lib/chef/application/solo.rb:231:in `run_application'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.0/lib/chef/application.rb:73:in `run'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.0/bin/chef-solo:25:in `<top (required)>'
/usr/bin/chef-solo:23:in `load'
/usr/bin/chef-solo:23:in `<main>'

更新1 我正在为ruby-2.0.0-p247设置盒子,也许对早期版本的ruby有依赖性吗?

UPDATE 1 I'm provisioning the box with ruby-2.0.0-p247, is there a dependency on an earlier version of ruby maybe?

更新2 我已经尝试在新配置的盒子上使用ruby-1.9.3-p448,同样的问题,没有变化.

UPDATE 2 I've tried with ruby-1.9.3-p448, on a freshly provisioned box, same problem, no change.

能请你帮我吗?

谢谢

推荐答案

您尚未说明要使用的ohai和nginx食谱的哪个版本.

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).

安装 Berkshelf

gem install berkshelf

创建Berkshelf文件

Create a Berkshelf file

$ cat Berksfile

site :opscode

cookbook "nginx"

并使用它下载与nginx相关的所有食谱:

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

$ berks install -p cookbooks
Using 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)

-p"选项将它们放置在"cookbooks"子目录中:

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

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

这篇关于厨师食谱在nil:NilClass的ohai未定义方法`[]'上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆