chef-infrachef-template

get calling cookbook within chef custom resource


I have a cookbook my_service with a custom resource write_config. This resource is called from another cookbook node_a.

This works fine, but I would like to get rid of the calling_cookbook property.

Is there a way to automatically get the calling_cookbook name?

Solution

(Thank you coderanger!) The basic resource template seems to get evaluated in the context of the calling (node_a) cookbook (?).

Neat!


Solution

  • This is tracked automatically as new_resource.cookbook_name. You may need to to_s it because somehow it ends up a symbol sometimes but otherwise should be what you need.

    Also specifically for templates this is already the default behavior if you just remove the cookbook line.