From
https://docs.chef.io/resource_template.html
cookbook
Ruby Type: String
The cookbook in which a file is located (if it is not located in the current cookbook). The default value is the current cookbook.
The key is if it is not located in the current cookbook.
I’m guessing that your custom resource is placed in a library cookbook which does not have the template file?
In that case, you might need to supply the cookbook, it depends on whether Chef will create the resources used in your custom resource under the current cookbook, i.e. the cookbook name set to where you consume your custom resource, I don’t think Chef will use the cookbook name that contains the definition of the custom resource. You can determine whether it is the former or latter by putting a pry breakpoint in your custom resource or output the resources cookbook to the log (similar to below)
t = template '/etc/mflmrcscript' do
source '/etc/mflmrcscript.erb'
mode 0755
owner 'root'
group 'root'
variables(license_manager_path: license_manager_path)
end
puts t.cookbook
=begin
Or use log class
=end
Chef::Log.info("Cookbook #{t.cookbook}")
=begin
Or use log resource
=end
log ""Cookbook #{t.cookbook}"
If cookbook name is wrong then you’ll need to specify the cookbook name as an attribute in your custom resource, you could call it template_cookbook,
property :template_cookbook, kind_of: String
If you use an attribute called cookbook then it’ll conflict with the built in resource cookbook property and you will have to use new_resource.
The principal behind the old Lightweight Resource Providers (LWRP) was that the definition of the resource as described in the recipe file is passed in to your LWRP provider as new_resource. The provider is the actual implementation of your resource actions, in the provider you then load the current state of the resource, compare the new resource against the current state of the resource, i.e. the desired state (new resource) and current state, the provider then works towards changing the resource into the desired state (as defined by new_resource). Ordinarily you need to do this with custom resources unless the property name
Additional info, Chef stores files/templates etc in the cookbook collection manifests and does a lookup into the manifest to retrieve the relevant files, hence cookbook is needed.
We’ve written quite a few cookbooks that wrap community cookbooks and use our own template files rather than the one’s supplied by the community, we can do this very easily in a recipe file thanks to the resources method …
=begin
In recipe file ...Use our own template for xxxx
=end
resources("template[#{node['apache']['dir']}/apache.conf]").cookbook "our_cookbook"
Hope these pointers help, first thing to do is check to see what the value of cookbook in your custom resources template.