首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >厨师:在尝试添加“节点”时,“节点”上的未定义节点属性或方法`<<‘

厨师:在尝试添加“节点”时,“节点”上的未定义节点属性或方法`<<‘
EN

Stack Overflow用户
提问于 2015-03-05 13:26:13
回答 1查看 3.9K关注 0票数 1

在postgresql食谱的属性文件中,我有:

代码语言:javascript
运行
复制
default['postgresql']['pg_hba'] = {
    :comment => '# IPv4 local connections',
    :type => 'host',
    :db => 'all',
    :user => 'all',
    :addr => '127.0.0.1/32',
    :method => 'md5'
}

我希望我的菜谱自动地将我的服务器添加到pg_hga配置文件中,如下所示:

代码语言:javascript
运行
复制
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'

但我收到了一个错误:

代码语言:javascript
运行
复制
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'
EN

Stack Overflow用户

回答已采纳

发布于 2015-03-05 15:03:18

你的问题是:

代码语言:javascript
运行
复制
node['postgresql']['pg_hba'] << {

这样,您就可以访问该属性进行读取。

假设您希望保持默认级别,则必须使用以下默认方法:

代码语言:javascript
运行
复制
node.default['postgresql']['pg_hba'] << { ... }

这将调用默认方法(如在属性文件中)来添加条目。

要使其工作,第一个属性声明应该是一个数组(或散列哈希),如下所示:

代码语言:javascript
运行
复制
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
票数 1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28878933

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档