5

我正在编写一本厨师食谱,在我的 vagrant box 上设置一个带有 nginx postgresql 和 unicorn 的 vanilla ubuntu 12.04.2,但是我遇到了 nginx 问题,有一个例外

undefined method `[]' for nil:NilClass

安装时似乎与 ohai 配置有关。

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

https://github.com/DonGiulio/mychef

这是 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​​?

更新 2 我ruby-1.9.3-p448在一个新配置的盒子上尝试过,同样的问题,没有变化。

请你帮助我好吗?

谢谢,

4

4 回答 4

5

您还没有说明您使用的是哪个版本的 ohai 和 nginx 食谱。

虽然我无法回答您的问题,但我可以提供一些关于使用依赖管理器管理您的食谱的建议(想想用于食谱的捆绑器)。

安装Berkshelf

gem install berkshelf

创建一个 Berkshelf 文件

$ cat Berksfile

site :opscode

cookbook "nginx"

并使用它来下载与 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”子目录中:

$ ls -d cookbooks/*
cookbooks/apt       
cookbooks/build-essential  
cookbooks/ohai     
cookbooks/runit
cookbooks/bluepill  
cookbooks/nginx            
cookbooks/rsyslog  
cookbooks/yum
于 2013-11-19T20:50:20.743 回答
0

我遇到了同样的错误。您可能会找到解决此问题的 3 个其他解决方案,并解释为什么它会在 stackoverflow 上发生

为那些使用 Vagrant 的人提一个:只需通过 Vagrantfile "chef.add_recipe()" 包含食谱。

使用 Berkshelf 显然可以解决问题,我真的很喜欢它。想想我们应该节省那些不想安装新工具的人的时间。

于 2013-12-05T09:44:27.847 回答
0

碰到这个试图使用社区关系食谱。通过在我的 metadata.rb 中指定最新版本的 nginx 食谱来解决它: depends 'nginx', '>= 2.7.6'

Nexus 食谱 metadata.rb 指定: depends "nginx", ">= 1.8.0"

因此,除非您指定较新的版本,否则厨师在解析 deps 时似乎会选择 1.8.0。

于 2016-11-02T15:03:09.993 回答
-1

看起来缺少 ruby​​ 库,我通过在 Ubuntu 上运行以下命令安装了 ruby​​,它开始为我工作

apt-get install ruby
于 2013-11-30T09:00:59.560 回答