Search code examples
chef-infrachef-recipecookbookrecipelwrp

Scoping Chef LWRPs back to the cookbook containing the resource being called


I have a cookbook that contains a LWRP and some files in the "files" folder.

cookbook_file put_it_here do
  source myfile
end

A recipe in another cookbook that calls this resource will look in its own cookbook's "files" dir, not the files of the cookbook where the resource is located.

I tried using cookbook_name, but that still resolves to the recipe calling the resource so the code below does not work.

cookbook_file put_it_here do
  source myfile
  cookbook cookbook_name
end

How can I refer to the files dir of the cookbook the resource is located in without having to hard code it?


Solution

  • Unfortunately you just have to hard code it.

    We don't expose this directly for LWRPs, though you could technically parse it out of self.class.to_s. For Poise I've got a thing that reverse-engineers the cookbook name based on manifest data, but that doesn't probably help you unless you want to drink my kool-aid.