【问题标题】:Chef: Modify existing resource from another cookbook厨师:从另一个食谱修改现有资源
【发布时间】:2017-10-20 21:08:32
【问题描述】:

我有两本食谱:elasticsearch 和 curator。

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

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

我需要在 curator cookbook 上修改它并添加一行:

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

我该怎么做?

【问题讨论】:

  • 您是否尝试过使用edit_resource!
  • 我没有!能举个小例子吗?

标签: resources chef-infra


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-27
    • 1970-01-01
    • 2015-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-25
    • 1970-01-01
    相关资源
    最近更新 更多