【问题标题】:no method error for nginx chef recipenginx 厨师食谱没有方法错误
【发布时间】:2014-01-07 23:42:37
【问题描述】:

我正在尝试使用 Chef opscode 网站上的 Nginx 配方,http://community.opscode.com/cookbooks/nginx

当我运行配方时,它触发了一个无方法错误,该错误可追溯到 source.rb 中的这行代码。这是跟踪中提到的第 28 行。

nginx_url = node['nginx']['source']['url'] ||
  "http://nginx.org/download/nginx-#{node['nginx']['source']['version']}.tar.gz"

谁能解释可能是什么问题?我正在关注这个 Railscast http://railscasts.com/episodes/339-chef-solo-basics?view=asciicast,其中配方(显然是旧版本)适用于 Ryan。

NoMethodError: undefined method `[]' for nil:NilClass
/var/chef/cookbooks/nginx/recipes/source.rb:28:in `from_file'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/mixin/from_file.rb:30:in `instance_eval'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/mixin/from_file.rb:30:in `from_file'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/cookbook_version.rb:346:in `load_recipe'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/run_context.rb:151:in `load_recipe'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/run_context.rb:132:in `block in include_recipe'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/run_context.rb:131:in `each'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/run_context.rb:131:in `include_recipe'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/dsl/include_recipe.rb:26:in `include_recipe'
/var/chef/cookbooks/main/recipes/default.rb:4:in `from_file'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/mixin/from_file.rb:30:in `instance_eval'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/mixin/from_file.rb:30:in `from_file'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/cookbook_version.rb:346:in `load_recipe'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/run_context.rb:151:in `load_recipe'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/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.4/lib/chef/run_context/cookbook_compiler.rb:137:in `each'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/run_context/cookbook_compiler.rb:137:in `compile_recipes'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/run_context/cookbook_compiler.rb:74:in `compile'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/run_context.rb:86:in `load'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/client.rb:224:in `setup_run_context'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/client.rb:467:in `do_run'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/client.rb:200:in `run'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/application.rb:190:in `run_chef_client'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/application/solo.rb:239:in `block in run_application'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/application/solo.rb:231:in `loop'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/application/solo.rb:231:in `run_application'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/application.rb:73:in `run'

【问题讨论】:

    标签: ruby chef-infra


    【解决方案1】:

    很抱歉迟到了。如果您在需要将其作为依赖项输入 metadata.rb 之前没有解决此问题

    如下:

    name             'casino-saga'
    maintainer       'Mikael Henriksson'
    license          'All rights reserved'
    description      'Installs/Configures casino-saga servers'
    long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
    version          '0.1.0'
    
    depends 'apt'
    depends 'build-essential'
    depends 'ohai'
    depends 'runit'
    depends 'nginx'
    depends 'rbenv'
    depends 'postgresql'
    

    【讨论】:

      【解决方案2】:

      nodenode['nginx']node['nginx']['source'] 中的任何一个都是 nil

      【讨论】:

        【解决方案3】:

        也许我来晚了,但我已经通过下载 ohai 食谱并将其添加到我的 Vagrantfile 解决了这个问题。

        (是的,我通过 Vagrant 使用 Chef)

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-08-04
          • 2012-11-01
          相关资源
          最近更新 更多