I have a cookbook let's say the name of my cookbook is check
and I am trying to build a custom resource by having the file in the following directory structure : check/resources/myresource.rb
. In this myresource.rb
file I need to use a custom resource from another cookbook line
. How do I use the resource from line
cookbook in myresource.rb
?
Is it possible to use a custom resource from some cookbook to create a custom resource in your own cookbook?
1k views Asked by blueowl At
2
There are 2 answers
3
On
You can do it exactly the same way you would, if you wanted to use it in your recipe.
- Depend on the cookbook that has another custom resource defined:
# metadata.rb
depends 'line', '~> X.Y' # add this line, replacing X and Y with line cookbook version
- Use custom resource. You can use it in recipe or in your custom resource, anywhere you can generally use resources. (I used
line_resource
as an example, the real name is different, depending in what file inline
cookbook it was declared.)
# check/resources/myresource.rb
action :some_action do
line_resource [...] do
[...]
end
end
Based on what @Draco already mentioned, the two steps described by him are required steps. In addition to that, the inclusion of the cookbook needs to be done when you call the custom resource in your recipe.
Then while calling it in the recipe you can mention the name of the cookbook that you want to include.
In this way, at convergence, all resources will be available for operations.