你如何在厨师中设置节点配置?

How do you set node configurations in chef?

我有一本安装 elasticsearch 的包装器食谱。

说明书通过使用以下语法支持动态配置文件:

node.elasticsearch[:custom_config]

https://github.com/elastic/cookbook-elasticsearch/blob/f7fb420a8641cbfa3e76acd64714dcc16ac6e274/templates/default/elasticsearch.yml.erb#L9-L16

当我尝试在我的包装器食谱中实现它时,出现以下错误:

   12>> node[:elasticsearch][:custom_config] = {'indices.breaker.fielddata.limit' => '75%'}
        13:  node[:elasticsearch][:custom_config] = {'indices.fielddata.cache.size' => '65%'}
        14:  
        15:  
        16:  
        17:  # Work around for issue when no ssl certs are present
        18:  # https://github.com/elastic/cookbook-elasticsearch/commit/7bdaffc0a1b8e2ae17dc9ab961a468daf9825b98
        19:  # normal[:elasticsearch][:nginx][:ssl][:cert_file] = nil
        20:  # normal[:elasticsearch][:nginx][:ssl][:key_file] = nil
        21:  


       Running handlers:

       Running handlers complete

       [2015-05-01T17:10:42+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
       Chef Client failed. 0 resources updated in 0.969790492 seconds
       [2015-05-01T17:10:42+00:00] ERROR: Node attributes are read-only when you do not specify which precedence level to set. To set an attribute use code like `node.default["key"] = "value"'
       [2015-05-01T17:10:42+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

根据我的研究,似乎在 chef 11 和更新版本上,您必须像这样指定您的范围:

node.set[:elasticsearch][:custom_config] { 'foo' => 'bar' }
node.default[:elasticsearch][:custom_config] { 'foo' => 'bar' }

不幸的是,在我的 default.rb 中使用这些语法不起作用,因为 foo 和 bar 从未出现在我的配置中。

覆盖包装器说明书中节点值的正确方法是什么?

更新

我也尝试过以下语法,但没有成功。

default['elasticsearch']['custom_config'] = {
  'indices.breaker.fielddata.limit' => '75%',
  'indices.fielddata.cache.size' => '65%'
}

实现它的代码位于此处:

https://github.com/elastic/cookbook-elasticsearch/blob/1e48dc99816e09ac96e2e850e70768fab6c82b89/templates/default/elasticsearch.yml.erb#L161-L163

**更新 2 **

看来我的 elasticsearch.yaml 与 github 上的不一样

我注意到我的有一行 #####Security#### 而 github 没有。另外 github 有 #####custom#### 而我的没有。两者都是食谱的 0.3.13 版。

http://pastebin.com/1nCjJY1d https://github.com/elastic/cookbook-elasticsearch/blob/v0.3.13/templates/default/elasticsearch.yml.erb

看起来它在工作,但是有 2 个 elasticsearch 文件。

/usr/local/elasticsearch/conf/elasticsearch.yml
/usr/local/etc/elasticsearch/elasticsearch.yml

第一个没用,第二个更新了。

Related github issue