Answers: <p>There are a lot of specifics but the overall pattern we use is "wrap and extend". The general idea is to make a cookbook that depends on the community cookbook, usually named <code>mycompany_originalthing</code>, and then make recipes in that which call <code>include_recipe 'originalthing::whatever'</code> but with either more stuff added before/after or with calls to things like <code>edit_resource</code> to change resources. Avoid <code>edit_resource</code> when possible since it leads to brittle code, but it is there if you need it. You can also use wrapper cookbooks to set attributes, subclass or wrap custom resources, and so on.</p>
  
  <p>For the specific case of "I need to tweak a template in a community recipe" it would look like this:</p>
  
  <pre><code>include_recipe 'original::whatever'
  
  edit_resource!(:template, '/path/to/something') do
    source 'mytemplate.erb'
    cookbook 'mycompany_original'
  end
  </code></pre>
  
  <p>You can find more details about <code>edit_resource</code> and friends at <a href="https://coderanger.net/rewind/" rel="noreferrer">https://coderanger.net/rewind/</a></p>
  
  <p>With cookbooks based around custom resources instead of recipes, things can get more complex but the specifics depend a lot on the how exactly the cookbook you are extending is written.</p>
  
Answers: CC BY-SA 3.0
Answers: 2017-03-02T02:54:20.523Z
Answers: This is the pattern we follow and it usually works until tweaking the community cookbook has gotten too hard and it's easier to just rewrite it from scratch.
Answers: Travis Thompson
Answers: CC BY-SA 3.0
Answers: 2017-03-02T04:21:22.893Z
Answers: Great! Didn't even know they changed the old buggy rewind thing to something that is part of Chef.
Answers: Evgeny Zislis
Answers: CC BY-SA 3.0
Answers: 2017-03-05T07:57:10.247Z
Answers: Sorry to ask, but your username is also included in the link you mentioned ... Which makes me wonder if you have any affiliation with that link. If so, are you familiar with SE policies about includiing an appropriate "disclosure" about that (to be included in your answer also)?
Answers: Pierre.Vriens
Answers: CC BY-SA 3.0
Answers: 2017-03-05T08:20:57.817Z
Answers: @Pierre.Vriens in the context of the Chef world, my blog is roughly equivalent to the official docs.  Check my history on SO if you want confirmation :)
Answers: coderanger
Answers: CC BY-SA 3.0
Answers: 2017-03-05T08:29:14.983Z
Answers: (in this case I don't link to the official docs because they contain syntax errors for this API)
Answers: coderanger
Answers: CC BY-SA 3.0
Answers: 2017-03-05T08:48:10.313Z
Answers: Your link is fine (and "I" actually knew that already), but still I think you should add something as I suggested before (eg: change "friends at" to "friends in my bog at").
Answers: Pierre.Vriens
Answers: CC BY-SA 3.0
Answers: 2017-03-02T01:50:59.160Z
Answers: 2017-03-02T01:50:59.160Z
Answers: coderanger
Body: <p>With 3200+ cookbooks available in Chef supermarket, often there is already a cookbook that covers the need I need to solve.</p>
  
  <p>Almost every time there is some change required to a template, or a variable, or a resource in an existing cookbook.</p>
  
  <p>What are the steps to override and/or improve existing cookbooks? Without forking their code, and retaining the ability to get version updates in the future.</p>
  
Comments: CC BY-SA 3.0
Comments: 2017-05-09T12:06:37.720Z
Comments: Most cookbooks have a certain number of attributes which can simply be set while building a wrapper cookbook.  You usually don't have to "override" anything to make expected tweaks.
Comments: chicks
Tags: <chef>
Title: What steps could be taken to inherit and override some parts of a Chef cookbook?
UserDisplayName: Evgeny Zislis
ThreadText: # What steps could be taken to inherit and override some parts of a Chef cookbook?
  
  (Asked by: username_0 on 2017-03-02)
  
  With 3200+ cookbooks available in Chef supermarket, often there is already a cookbook that covers the need I need to solve.
  
  Almost every time there is some change required to a template, or a variable, or a resource in an existing cookbook.
  
  What are the steps to override and/or improve existing cookbooks? Without forking their code, and retaining the ability to get version updates in the future.
  
  **Tags:** chef
  
  > **Comments:**
  > **username_1**: Most cookbooks have a certain number of attributes which can simply be set while building a wrapper cookbook.  You usually don't have to "override" anything to make expected tweaks.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2017-03-02. Score: 13 | Accepted answer
  
  There are a lot of specifics but the overall pattern we use is "wrap and extend". The general idea is to make a cookbook that depends on the community cookbook, usually named `mycompany_originalthing`, and then make recipes in that which call `include_recipe 'originalthing::whatever'` but with either more stuff added before/after or with calls to things like `edit_resource` to change resources. Avoid `edit_resource` when possible since it leads to brittle code, but it is there if you need it. You can also use wrapper cookbooks to set attributes, subclass or wrap custom resources, and so on.
  
  For the specific case of "I need to tweak a template in a community recipe" it would look like this:
  
  ```
  include_recipe 'original::whatever'
  
  edit_resource!(:template, '/path/to/something') do
    source 'mytemplate.erb'
    cookbook 'mycompany_original'
  end
  
  ```
  
  You can find more details about `edit_resource` and friends at <https://username_2.net/rewind/>
  
  With cookbooks based around custom resources instead of recipes, things can get more complex but the specifics depend a lot on the how exactly the cookbook you are extending is written.
  
  > **Comments:**
  > **username_3**: This is the pattern we follow and it usually works until tweaking the community cookbook has gotten too hard and it's easier to just rewrite it from scratch.  
  > **username_0**: Great! Didn't even know they changed the old buggy rewind thing to something that is part of Chef.  
  > **username_4**: Sorry to ask, but your username is also included in the link you mentioned ... Which makes me wonder if you have any affiliation with that link. If so, are you familiar with SE policies about includiing an appropriate "disclosure" about that (to be included in your answer also)?  
  > **username_2**: @username_4 in the context of the Chef world, my blog is roughly equivalent to the official docs.  Check my history on SO if you want confirmation :)  
  > **username_2**: (in this case I don't link to the official docs because they contain syntax errors for this API)  
  > **username_4**: Your link is fine (and "I" actually knew that already), but still I think you should add something as I suggested before (eg: change "friends at" to "friends in my bog at").  
  
  ---
  
  