[英]Chef: Undefined node attribute or method `<<' on `node' when trying to add
[英]in chef: Undefined node attribute or method `<<' on `node'
測試不在產品中的另一個令人沮喪的問題。
代碼是問題,將字符串附加到節點屬性。
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
如上所述,這可以在測試廚房中使用,也可以在生產中使用廚師用殼,但是在生產中運行配方會引發以下情況:
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:未定義的節點屬性或試圖添加時在“ node”上使用方法“ <<” )指的是不在node
對象上使用優先級,但我確實與之不同。鏈接中顯示的內容。
我可能在這里錯過了一些愚蠢的東西,但是它曾經可以工作,現在仍然可以在廚房工作,所以我沒有地方去看。 難道是某種奇怪的編譯問題不會在chef-zero
復制嗎?
您可能需要做的是:
node.normal ['tom-ssh'] ['allow_groups'] = DeepMerge.merge(node.normal ['tom-ssh'] ['allow_groups']。to_hash,[“ bots”]。to_hash)
我認為您想要的邏輯更像這樣
node.normal['tom-ssh']['allow_groups'] ||= []
node.normal['tom-ssh']['allow_groups'] |= %w{bots}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.