Chef infra 未定义的方法'each';for nil:NilClass在chef recipe中迭代哈希时
我并不是一个真正的厨师专家,我很可能忽略了一些愚蠢的事情。我试图迭代厨师食谱(chef client 12.5.1)中的一个散列,并接收到nil:NilClass的未定义的方法'each' 我不知道为什么,但也许我已经盯着它看太久了。感谢您的帮助 属性 配方错误 注意:我在pp中添加了故障排除功能Chef infra 未定义的方法'each';for nil:NilClass在chef recipe中迭代哈希时,chef-infra,chef-recipe,Chef Infra,Chef Recipe,我并不是一个真正的厨师专家,我很可能忽略了一些愚蠢的事情。我试图迭代厨师食谱(chef client 12.5.1)中的一个散列,并接收到nil:NilClass的未定义的方法'each' 我不知道为什么,但也许我已经盯着它看太久了。感谢您的帮助 属性 配方错误 注意:我在pp中添加了故障排除功能 undefined method `each' for nil:NilClass Cookbook Trace: --------------- /tmp/kitchen
undefined method `each' for nil:NilClass
Cookbook Trace:
---------------
/tmp/kitchen/cache/cookbooks/ga_haproxy_default/recipes/default.rb:12:in `block in from_file'
/tmp/kitchen/cache/cookbooks/ga_haproxy_default/recipes/default.rb:8:in `each'
/tmp/kitchen/cache/cookbooks/ga_haproxy_default/recipes/default.rb:8:in `from_file'
Relevant File Content:
----------------------
/tmp/kitchen/cache/cookbooks/ga_haproxy_default/recipes/default.rb:
5: # Copyright (c) 2016 Sean McGowan, All Rights Reserved.
6: require 'pp'
7:
8: node['haproxy'].each do |instance_name, inst|
9: ga_haproxy instance_name
10:
11: pp inst['frontends']
12>> inst['frontends'].each do |fe_name, frontend|
13: ga_haproxy_frontend fe_name do
14: instance_name instance_name
15: socket frontend['socket']
16: default_backend frontend['default_backend']
17: action :enable
18: end
19: end
20:
21: node['haproxy-shared'].each do |be_name, backend|
漂亮的打印显示了ruby过程中变量的内容
Synchronizing Cookbooks:
- ga_haproxy (0.1.1)
- ga_haproxy_default (0.1.0)
Compiling Cookbooks...
{"main"=>{"socket"=>"*:5000", "default_backend"=>"default-backend"},
"http"=>{"socket"=>"*:80", "default_backend"=>"default-backend"}}
{"main"=>{"socket"=>"*:6000", "default_backend"=>"test-backend"},
"https"=>{"socket"=>"*:443", "default_backend"=>"test-backend"}}
inst最初是一个实例,但我对它进行了更改,以查看它是否偶然与某个对象发生冲突;然而,这些内容在irb中是可接受的。谁能告诉我我做错了什么
编辑:我还对chef client 12.14.89运行了它,得到了相同的结果。可能是
默认['haproxy']['shared']
行没有前端
键。你的意思是把它也改成haproxy shared吗?打印出实例名称
,以确保正确。请记住nil.to_s==''
,因此您可能看不到预期的日志记录。Doh!我猜昨天在屏幕前的时间太长了。谢谢你的眼睛@coderanger!
Synchronizing Cookbooks:
- ga_haproxy (0.1.1)
- ga_haproxy_default (0.1.0)
Compiling Cookbooks...
{"main"=>{"socket"=>"*:5000", "default_backend"=>"default-backend"},
"http"=>{"socket"=>"*:80", "default_backend"=>"default-backend"}}
{"main"=>{"socket"=>"*:6000", "default_backend"=>"test-backend"},
"https"=>{"socket"=>"*:443", "default_backend"=>"test-backend"}}