As a general practice when using community cookbooks I try not to, unless absolutely necessary, update the code in the cookbook.  This makes updating the version of the cookbook in your git repository to the latest and greatest a bit easier.  Sometimes the community cookbook does not behave exactly the way I want it to behave.

To get around these issues I use wrapper cookbooks to add in the features or changes I need.  In the wrapper cookbook, the code below will override a template already declared in the community cookbook.

include_recipe "community_cookbook"

  override = resources(:template => "/etc/init.d/run_script")
  override.cookbook "wrapper_cookbook"
rescue Chef::Exceptions:ResourceNotFound
  Chef::Log.warn "template not found

The template file will need to exist in the templates directory of the wrapper cookbook. The metadata.rb file for the wrapper cookbook also needs to be modified to include a dependency for the community cookbook.

Leave a comment

Your email address will not be published. Required fields are marked *