【发布时间】:2018-01-22 21:11:44
【问题描述】:
另一个令人沮丧的问题是测试而不是生产。
代码是问题将字符串附加到节点属性。
if node['tom-ssh']['allow_groups']
if !node['tom-ssh']['allow_groups'].include?("bots")
node.normal['tom-ssh']['allow_groups'] << "bots"
end
else
node.normal['tom-ssh']['allow_groups'] = ["bots"]
end
如上所述,这在测试厨房中有效,在生产中的 chef-shell 中有效,但在 prod 中运行配方会引发以下问题:
NoMethodError
-------------
Undefined node attribute or method `<<' on `node'. To set an attribute, use `<<=value' instead.
Cookbook Trace:
---------------
/var/chef/cache/cookbooks/tom-users/recipes/reboot_bot.rb:22:in `from_file'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/run_context.rb:347:in `load_recipe'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/run_context.rb:303:in `block in include_recipe'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/run_context.rb:302:in `each'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/run_context.rb:302:in `include_recipe'
/var/chef/cache/cookbooks/tom-security-patches/recipes/default.rb:8:in `from_file'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/run_context.rb:347:in `load_recipe'
Relevant File Content:
----------------------
/var/chef/cache/cookbooks/tom-users/recipes/reboot_bot.rb:
15: '/sbin/reboot'
16: ]
17: end
18:
19: # allow 'bots' to ssh log in
20: if node['tom-ssh']['allow_groups']
21: if !node['tom-ssh']['allow_groups'].include?("bots")
22>> node.normal['tom-ssh']['allow_groups'] << "bots"
23: end
24: else
25: node.normal['tom-ssh']['allow_groups'] = ["bots"]
26: end
27:
我发现的关于该主题的问题(例如Chef: Undefined node attribute or method `<<' on `node' when trying to add)是指没有在node 对象上使用优先级,但我这样做了,只是与链接中显示的不同。
我可能在这里遗漏了一些愚蠢的东西,但它以前工作过,现在还在厨房里工作,所以我没地方看。会不会是某种在chef-zero 中无法复制的奇怪编译问题?
【问题讨论】:
-
您使用的是什么版本的 Chef?
-
最新 (12.17.44)。但我试过降级到其他版本,结果是一样的
标签: chef-infra