I am not loading <cookbook::recipe> because I have already seen it

Hi folks,

I am a relatively new Chef user running chef solo on linux. I’m running into a
problem when trying to invoke a community cookbook/recipe multiple times with
different databags. I’m hoping to find some advice/help.

Some details:

I have a “common” role definition and its runlist contains a wrapper recipe (a)
which loads some data from a databag (b) and uses “include_recipe” to
load/invoke a 3rd party cookbook/recipe ©. This all works as expected. I
also have a role specific role definition with a runlist that contains a
different wrapper recipe (d) which, similarly, loads some data from a DIFFERENT
databag (e) and uses “include_recipe” to load/invoke the SAME 3rd party
cookbook/recipe ©. What I’m finding is that the third party recipe doesn’t
get invoked by “include_recipe” the second time.

When I run in debug mode, I see that my combined runlist is accurate, but later
down the log, I see the message, “I am not loading cookbook::recipe because I
have already seen it.”

I realize that chef converges such that recipes don’t get loaded twice, but I’m
not sure how to reconcile that convergence with the results that I’m after. Is
there a way to invoke the loaded recipe a second time (with different data)?
Is my model/understanding flawed? Am I doing it wrong?

I did come across this old bug which describes a similar problem, but the
workaround doesn’t seem to work anymore and the proper solution isn’t very
clear (to a newbie).

https://tickets.opscode.com/browse/CHEF-1406

Thanks in advance for any constructive advice.

This is exactly the kind of thing I'd use a definition to do. In a post I
wrote earlier this year about cookbook development, I discuss the use of a
definition in our 'chef-splunk' cookbook.

Documentation about definitions here:

http://docs.getchef.com/essentials_cookbook_definitions.html

Hope this helps,
Joshua

On Wed, Aug 6, 2014 at 2:23 PM, Jason Newblanc <
jason.newblanc@servicenow.com> wrote:

Hi folks,

I am a relatively new Chef user running chef solo on linux. I'm running
into a
problem when trying to invoke a community cookbook/recipe multiple times
with
different databags. I'm hoping to find some advice/help.

Some details:

I have a "common" role definition and its runlist contains a wrapper
recipe (a)
which loads some data from a databag (b) and uses "include_recipe" to
load/invoke a 3rd party cookbook/recipe (c). This all works as expected.
I
also have a role specific role definition with a runlist that contains a
different wrapper recipe (d) which, similarly, loads some data from a
DIFFERENT
databag (e) and uses "include_recipe" to load/invoke the SAME 3rd party
cookbook/recipe (c). What I'm finding is that the third party recipe
doesn't
get invoked by "include_recipe" the second time.

When I run in debug mode, I see that my combined runlist is accurate, but
later
down the log, I see the message, "I am not loading cookbook::recipe
because I
have already seen it."

I realize that chef converges such that recipes don't get loaded twice,
but I'm
not sure how to reconcile that convergence with the results that I'm
after. Is
there a way to invoke the loaded recipe a second time (with different
data)?
Is my model/understanding flawed? Am I doing it wrong?

I did come across this old bug which describes a similar problem, but the
workaround doesn't seem to work anymore and the proper solution isn't very
clear (to a newbie).

https://tickets.opscode.com/browse/CHEF-1406

Thanks in advance for any constructive advice.

those warnings are from a stages that are before chef execution. All
recipes in chef gets compiled into a flat resource list. Then the resource
list is executed one by one. First phase is called compilation. As each of
the recipes gets compiled (recipe name -> resource list) its added in
loaded_recipes place holder (which internally used to check whether a
recipe needs to be included or not).

chef is raw ruby, so you can remove that recipe using the internal api.
this will be brittle (what if chef api changes?) also because the
resources inside the recipes are already added will be duplicated (rather
cloned) and the net outcome can be even more unpredictable (behavior of
notifications, resource cloning will depend up provider/resource
implementations ),

what exactly you are trying to do ? may be theres a cleaner way to do it,

cheers
ranjib

On Wed, Aug 6, 2014 at 1:23 PM, Jason Newblanc <
jason.newblanc@servicenow.com> wrote:

Hi folks,

I am a relatively new Chef user running chef solo on linux. I'm running
into a
problem when trying to invoke a community cookbook/recipe multiple times
with
different databags. I'm hoping to find some advice/help.

Some details:

I have a "common" role definition and its runlist contains a wrapper
recipe (a)
which loads some data from a databag (b) and uses "include_recipe" to
load/invoke a 3rd party cookbook/recipe (c). This all works as expected.
I
also have a role specific role definition with a runlist that contains a
different wrapper recipe (d) which, similarly, loads some data from a
DIFFERENT
databag (e) and uses "include_recipe" to load/invoke the SAME 3rd party
cookbook/recipe (c). What I'm finding is that the third party recipe
doesn't
get invoked by "include_recipe" the second time.

When I run in debug mode, I see that my combined runlist is accurate, but
later
down the log, I see the message, "I am not loading cookbook::recipe
because I
have already seen it."

I realize that chef converges such that recipes don't get loaded twice,
but I'm
not sure how to reconcile that convergence with the results that I'm
after. Is
there a way to invoke the loaded recipe a second time (with different
data)?
Is my model/understanding flawed? Am I doing it wrong?

I did come across this old bug which describes a similar problem, but the
workaround doesn't seem to work anymore and the proper solution isn't very
clear (to a newbie).

https://tickets.opscode.com/browse/CHEF-1406

Thanks in advance for any constructive advice.