user3440013
user3440013

Reputation: 71

chef resource cloning - what is it?

I am trying to get more information on what chef resource cloning exactly is. I see them during my chef-client run but don’t know what they mean.

I’ve seen this blog below on resource cloning but I still can’t make sense of what it does. Does anyone have further information on this topic? Can’t find much else using google.

http://scottwb.com/blog/2014/01/24/defeating-the-infamous-chef-3694-warning/

Upvotes: 6

Views: 1325

Answers (2)

notapatch
notapatch

Reputation: 7173

Deprecation: Resource Cloning (CHEF-3694)

Chef allows resources to be created with duplicate names, rather than treating that as an error. This means that several cookbooks can request the same package be installed, without needing to carefully create unique names. This is problematic because having multiple resources named the same makes it impossible to safely deliver notifications to the right resource.

The behaviour in Chef 12 and earlier, which is now deprecated, is that we will try to clone the existing resource, and then apply any properties from the new resource. For example:

file "/etc/my_file" do
  owner "ken"
end

file "/etc/my_file" do
  mode "0755"
end

will result in the second instance having the following properties:

file "/etc/my_file" do
  owner "ken"
  mode "0755"
end

Resource cloning was deprecated in Chef 10.18.0 and will be removed in Chef 13.

Upvotes: 1

Gleb M Borisov
Gleb M Borisov

Reputation: 607

chef-client will merge resource definitions by their type and name (service[apache2] in your example). If you're working on wrapper cookbook check this great article: http://www.getchef.com/blog/2013/12/03/doing-wrapper-cookbooks-right from Julian Dunn.

Anyway, you can modify previously defined resources. In your case:

resources('service[apache2]').action [:enable, :start]

This will modify already defined resource service[apache2] and hide resource cloning warnings.

Upvotes: 1

Related Questions