resources - Chef : Modify existing resource from another cookbook

标签 resources chef-infra

我有两本 cooking 书:elasticsearch 和 curator。

Elasticsearch 说明书安装并配置 Elasticsearch。以下资源(来自 elasticsearch Recipe )必须从 curator Recipe 进行修改:

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"])

我怎样才能做到这一点?

最佳答案

我最初打算向您指出 chef-rewind gem,但这实际上指向 edit_resource现已内置于 Chef 中的提供程序。一个基本的例子:

# 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 中的实际内容是已编辑资源的内容,修改后的内容!.

在没有完全测试您的案例的情况下,我假设可以以相同的方式使用提供程序,如下所示:

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

关于resources - Chef : Modify existing resource from another cookbook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46828306/

相关文章:

web-services - 有哪些好的资源可用于设计可良好扩展的基于 Web 服务的架构?

c++从资源中加载图像visual studios 2012在窗口上绘制

ruby - 捆绑安装使用不同的 Ruby 版本?

rubygems - 如何控制 Vagrant 用于配置虚拟机的 Chef 版本?

sql - Chef Cookbook 无法使用执行资源运行 sqllocaldb

ruby - Chef - 从 LWRP 中的其他操作调用操作

java - 从jar中读取资源文件

c# - 如何从包含其程序集和来自任何程序集的路径的 Uri 加载资源?

ruby-on-rails - Rails 4 - 设置,在创建新用户时自动创建配置文件

ruby-on-rails - RoR Heroku 的 Chef Recipe