Lechucico
Lechucico

Reputation: 2102

Chef: Modify existing resource from another cookbook

I have two cookbooks: elasticsearch and curator.

Elasticsearch cookbook installs and configure an elasticsearch. The following resource (from elasticsearch cookbook), has to be modified from curator 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

I need to modify it on curator cookbook and add a single line:

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

How I can do that?

Upvotes: 2

Views: 972

Answers (1)

vase
vase

Reputation: 349

I initially was going to point you to the chef-rewind gem, but that actually points to the edit_resource provider that is now built into Chef. A basic example of this:

# 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

If both of these are in the Chef run_list, the actual content within example.txt is that of the edited resource, modified content!.

Without fully testing your case, I'm assuming the provider can be utilized the same way, like so:

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

Upvotes: 2

Related Questions