Call a recipe from same cookbook


#1

Hi All,
This may be a very basic concept but I am not able to find the syntax to make it work. For Example, Is it possible to create a resource in recipe email.rb named emailme that can take a parameter that I can then feed into the recipe to email me a specific message from another recipe using notifies and only_if etc. So what I am trying to do is reuse code instead of writing an emailme resource in every recipe.
Thanks
Julian V


#2

recipes are not methods that can take parameters. generally you can
customize them via attributes. so, emailme recipe can declare a attribute
and use that as a message. from the other recipe you can use set the value
of the message attribute and then include_recipe ‘emailme’.

i prefer to use roles to customize the attribute.

On Sun, Sep 27, 2015 at 8:33 AM, Julian Varanini jvaranini@hotmail.com
wrote:

Hi All,

This may be a very basic concept but I am not able to find the syntax to
make it work. For Example, Is it possible to create a resource in recipe
email.rb named emailme that can take a parameter that I can then feed into
the recipe to email me a specific message from another recipe using
notifies and only_if etc. So what I am trying to do is reuse code instead
of writing an emailme resource in every recipe.

Thanks

Julian V


#3

Le 2015-09-27 17:33, Julian Varanini a écrit :

Hi All,

This may be a very basic concept but I am not able to find the syntax to make it work. For Example, Is it possible to create a resource in recipe email.rb named emailme that can take a parameter that I can then feed into the recipe to email me a specific message from another recipe using notifies and only_if etc. So what I am trying to do is reuse code instead of writing an emailme resource in every recipe.

Thanks

Julian V

Look at definition instead of recipe, you can define there a resource
which takes parameter and it’s code will be evaluated with the correct
parameters. Usually the definitions are used to call a group of
resources with some parameters.


#4

Foodcritic will give you a warning if you use definitions though, just as
an FYI

On 28 September 2015 at 00:37, Tensibai tensibai@iabis.net wrote:

Le 2015-09-27 17:33, Julian Varanini a écrit :

Hi All,

This may be a very basic concept but I am not able to find the syntax to
make it work. For Example, Is it possible to create a resource in recipe
email.rb named emailme that can take a parameter that I can then feed into
the recipe to email me a specific message from another recipe using
notifies and only_if etc. So what I am trying to do is reuse code instead
of writing an emailme resource in every recipe.

Thanks

Julian V

Look at definition instead of recipe, you can define there a resource
which takes parameter and it’s code will be evaluated with the correct
parameters. Usually the definitions are used to call a group of resources
with some parameters.