Include recipe twice

Hi ,

I have a recipe that includes a dependent recipe twice. Yet it only ever runs once. Is this normal? It does not seem like chef should care if I have a recipe that looks like this:

include_recipe[foo::bar]
[… do stuff…]
include_recipe[foo::bar]

If I run the above, only the first include_recipe is run. If I comment the first call then the second gets run. What am I not getting?

Cheers,
Florian

LEGAL DISCLAIMER
This communication and any attached documents are strictly confidential and/or legally privileged and they may not be used or disclosed by someone who is not a named recipient. If you have received this electronic communication in error please notify the sender by replying to this electronic communication inserting the word “misdirected” as the subject and delete this communication from your system.

Hey Florian,

That is limitation of include recipe (
http://docs.opscode.com/chef/dsl_recipe.html).

If a recipe is included more than once in a recipe, only the first
inclusion will be processed and any subsequent inclusion will be ignored.
For work around, you can create directly call the part you want to execute
from your Foo::bar by putting that part in the calling recipe and putting a
depend option in metadata.

Warm Regards,

Mrigesh Priyadarshi
Mob:-+91-720-402-2510

On Fri, Nov 22, 2013 at 1:11 PM, Florian Hehlen <
Florian.Hehlen@mri-group.com> wrote:

Hi ,

I have a recipe that includes a dependent recipe twice. Yet it only ever
runs once. Is this normal? It does not seem like chef should care if I
have a recipe that looks like this:

include_recipe[foo::bar]

[... do stuff...]

include_recipe[foo::bar]

If I run the above, only the first include_recipe is run. If I comment the
first call then the second gets run. What am I not getting?

Cheers,

Florian

LEGAL DISCLAIMER
This communication and any attached documents are strictly confidential
and/or legally privileged and they may not be used or disclosed by someone
who is not a named recipient. If you have received this electronic
communication in error please notify the sender by replying to this
electronic communication inserting the word "misdirected" as the subject
and delete this communication from your system.

On Fri, Nov 22, 2013 at 8:54 AM, Mrigesh Priyadarshi <
mrigeshpriyadarshi@gmail.com> wrote:

That is limitation of include recipe (
http://docs.opscode.com/chef/dsl_recipe.html).

If a recipe is included more than once in a recipe, only the first
inclusion will be processed and any subsequent inclusion will be ignored.
For work around, you can create directly call the part you want to execute
from your Foo::bar by putting that part in the calling recipe and putting a
depend option in metadata.

It's not a limitation - it's a feature. "include_recipe" lets you ensure
that some resources have been included in your Chef run. It is especially
useful when you have a recipe containing common resources, that many other
of your recipes depend upon - each can call include_recipe, and you will be
confident that the dependencies will always included at the right time - no
matter which recipe, or combination of recipes, you are using).

If you need a recipe to "run" more than once, you probably want to use a
Definition[1] or an LWRP[2].

Zac

1: http://docs.opscode.com/chef/essentials_cookbook_definitions.html
2: http://docs.opscode.com/chef/lwrps_custom.html