【问题标题】:Chef: modify existing resourceChef:修改现有资源
【发布时间】:2017-06-03 04:07:00
【问题描述】:

我当前的脚本如下所示:

es_conf = elasticsearch_configure 'elasticsearch' do
    allocated_memory '512m'
    configuration ({
        'http.port' => port,
            'cluster.name' => cluster_name,
            'node.name' => node_name,
            'bootstrap.memory_lock' => false,
            'discovery.zen.minimum_master_nodes' => 1
    })
end
es_conf.path_data data_location if data_location

elasticsearch_plugin 'repository-s3' do
  action :install
end

elasticsearch_plugin 'x-pack' do
  action :install
end

elasticsearch_configure 'elasticsearch' do
    configuration ({
        'http.port' => port,
        'cluster.name' => cluster_name,
        'node.name' => node_name,
        'bootstrap.memory_lock' => false,
        'discovery.zen.minimum_master_nodes' => 1,

        'xpack.monitoring.enabled' => true,
        'xpack.graph.enabled' => false,
        'xpack.watcher.enabled' => true
    })
end

它目前对我有用(我的意思是它可以根据需要配置弹性搜索)。不过,我知道这还不够好。我的意思是,我使用了两次elasticsearch_configure。问题是我首先需要配置elasticsearch,然后我需要安装x-pack,然后使用特定的x-pack值配置elasticsearch。

有什么想法可以让它更优雅一点吗?

没错,我的意思是我应该如何更改es_conf

【问题讨论】:

  • 你不能安装插件调用然后用所有设置调用elasticsearch_configure吗?另外,与问题无关,为什么不使用包含配置哈希的属性?

标签: chef-infra


【解决方案1】:

所以第二个资源将真正成为一个单独的资源,而不是第一个资源的修改。在 Chef 12 中,它将“克隆”第一个状态,但在 Chef 13 中,除了共享一个名称之外,这两者完全无关。

对此的通用修复是使用edit_resource,但由于您已经在本地拥有资源对象,您可以这样做:

es_conf.configuration.update({new: keys, go: here})

【讨论】:

  • Noah(又名 coderanger)太谦虚了。他对 edit_resource 的解释基本上是我在互联网上可以找到的唯一一个相当深入的解释,包括厨师文档和堆栈溢出。有关详细信息,请参阅coderanger.net/rewind
猜你喜欢
  • 1970-01-01
  • 2014-06-27
  • 1970-01-01
  • 1970-01-01
  • 2023-03-29
  • 1970-01-01
  • 1970-01-01
  • 2021-12-23
  • 2015-07-07
相关资源
最近更新 更多