Chef:从另一本cookbook修改现有资源

时间:2017-10-19 10:55:02

标签: resources chef

我有两本食谱:elasticsearch和curator。

Elasticsearch cookbook安装和配置elasticsearch。必须从策展人食谱中修改以下资源(来自elasticsearch cookbook):

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

我需要在策展人食谱上修改它并添加一行:

'path.repo' => (["/backups/s3_currently_dev", "/backups/s3_currently", "/backups/s3_daily", "/backups/s3_weekly", "/backups/s3_monthly"])

我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

我最初会指向chef-rewind gem,但实际上指的是现在内置于Chef的edit_resource提供程序。一个基本的例子:

# cookbook_a/recipes/default.rb
file 'example.txt' do
  content 'this is the initial content'
end

# cookbook_b/recipes/default.rb
edit_resource! :file, 'example.txt' do
  content 'modified content!'
end

如果这两个都在Chef run_list中,则example.txt中的实际内容是已编辑资源modified content!的内容。

如果没有对您的案例进行全面测试,我认为提供商可以采用相同的方式,如下所示:

edit_resource! :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,

        'path.repo' => ["/backups/s3_currently_dev", "/backups/s3_currently", "/backups/s3_daily", "/backups/s3_weekly", "/backups/s3_monthly"]
    })
end