Find wrapper CB files/default/foo instead of wrapped CB files/default/foo?


#1

We’re wrapping the clamav cookbook. It includes the following in a recipe:

cookbook_file node['clamav']['scan']['script']['path'] do
  source 'clamav-scan.sh'
  owner node['clamav']['user']
  group node['clamav']['group']
  mode '0555'
  only_if { node['clamav']['scan']['script']['enable'] }
end

How can I, in my wrapper cookbook, make my-wrapper/files/default/clamav-scan.sh be what is installed, not the one that comes with the clamav cookbook?


#2

In your wrapper cookbook, use edit_resource to specify the cookbook where to search the file:

edit_resource(:cookbook_file, node['clamav']['scan']['script']['path']) do
  cookbook_name cookbook_name
end

The right cookbook_name is a Recipe DSL helper containing the name of the current cookbook, so it should modify the resource to tell it to use your wrapper file instead of the original cookbook one.

Documentation for edit_recource: https://docs.chef.io/release/devkit/dsl_recipe.html#edit-resource
and for cookbook_name: https://docs.chef.io/release/devkit/dsl_recipe.html#cookbook-name


#3

Thanks! For those who come across this later, know that edit_resource is in Chef Client 12.10+ and the alternative for those of us not running 12.10+ yet is the deprecated chef-rewind helper gem at https://github.com/thommay/chef-rewind


#4

That should be cookbook cookbook_name, @Tensibai (and thanks again)