andiba
andiba

Reputation: 1568

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!

Upvotes: 2

Views: 1287

Answers (1)

coderanger
coderanger

Reputation: 54211

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.

Upvotes: 2

Related Questions