[英]Chef: Undefined node attribute or method `<<' on `node' when trying to add
在我的PostgreSQL配方屬性文件中,我有:
default['postgresql']['pg_hba'] = {
:comment => '# IPv4 local connections',
:type => 'host',
:db => 'all',
:user => 'all',
:addr => '127.0.0.1/32',
:method => 'md5'
}
我想將自己的服務器自動添加到pg_hga配置文件中,如下所示:
lambda {
if Chef::Config[:solo]
return (Array.new.push node)
end
search(:node, "recipes:my_server AND chef_environment:#{node.chef_environment} ")
}.call.each do |server_node|
node['postgresql']['pg_hba'] << {
:comment => "# Enabling for #{server_node['ipaddress']}",
:type => 'host',
:db => 'all',
:user => 'all',
:addr => "#{server_node['ipaddress']}/32",
:method => 'trust'
}
end
include_recipe 'postgresql'
但是我收到一個錯誤:
NoMethodError
-------------
Undefined node attribute or method `<<' on `node'
35: node['postgresql']['pg_hba'] << {
36: :comment => "# Enabling for #{server_node['ipaddress']}",
37: :type => 'host',
38: :db => 'all',
39: :user => 'all',
40: :addr => "#{server_node['ipaddress']}/32",
41: :method => 'trust'
42>> }
43: end
44:
45: include_recipe 'postgresql'
您的問題在這里:
node['postgresql']['pg_hba'] << {
這樣,您可以訪問屬性以進行讀取。
假設要保持默認級別,則必須使用默認方法,如下所示:
node.default['postgresql']['pg_hba'] << { ... }
這將調用默認方法(例如在屬性文件中)以添加條目。
為此,第一個屬性聲明應該是一個數組(或哈希的哈希),如下所示:
default['postgresql']['pg_hba'] = [{ # notice the [ opening an array
:comment => '# IPv4 local connections',
:type => 'host',
:db => 'all',
:user => 'all',
:addr => '127.0.0.1/32',
:method => 'md5'
}] # Same here to close the array
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.