run_context.include_recipe in a recipe within a role

I am using the "application" and "application_java" cookbooks, which
include_recipe "tomcat" in the LWRP, and i've brought the same code over to
an new cookbook for tomeeplus.

include_recipe is working fine if I only run the LWRP precisely one time.
if i run the LWRP more than one time, the include_recipe gets ignored.

this sounds like the same as the OP's issue.
I can't (easily) change the "base" cookbook, because the base cookbook is
"application"

On Thu, May 30, 2013 at 8:22 AM, Dorian Jaminais <
dorian.jaminais@perfect-memory.com> wrote:

Thank you all for your responses.

@peter : run_context.include_recipe works but only if the LWRP is called
once in during the chef_run.

I have included a recipe that installs all the dependencies for the LWRP
to work.
This works perfectly, even if still I don't understand why I had this
strange behavior with run_context.include_recipe

2013/5/30 Peter Donald peter@realityforge.org

Hi,

On Thu, May 30, 2013 at 8:43 AM, Daniel DeLeo dan@kallistec.com wrote:

Bringing this back to the OP's issue, I think including a recipe (the
normal
way) to install prerequisites of a LWRP is the right way to go about
it. If
you are doing wizardry with chef internals, either 1) you're making
something more complicated than it should be, 2) chef is making
something
more complicated than it should be, or 3) you're a wizard. So far, I'm
inclined to think that including recipes from a provider falls into
category
#1, since you can just as easily and elegantly solve the problem with a
role
(or role cookbook if that's your thing). Am I missing something?

I think it is more useful to see it as a failure of chef rather than a
failure of the user. i.e. Option 2.

In my mind LWRPs are a mechanism for creating composable
abstractions. Anything you can do in a recipe should be possible to do
in a LWRP. Where this is not true I would consider it a bug.

For this specific scenario I can easily see a use for it. In our
environment, many of our recipes are data driven. Data is collected
from search + rules + external systems (ldap/db etc) and then this is
interpreted and resources defined based on the data. So often we will
not know which LWRPs will be active (and thus which precursor recipes
should be included) until the data is interpreted.

That said I thought include_recipe worked from within LWRPs...

--
Cheers,

Peter Donald

--
Dorian JAMINAIS
System Administrator
+33 6 95 10 95 37
http://perfect-memory.com

https://twitter.com/semanticbushttp://www.facebook.com/pages/Perfect-Memory/155555567821817

Indeed that is exactly the same issue I had been running into.

For now I use to proposed workaround to include all those recipes from
another recipe.

Maybe I should open a ticket on that issue.

2013/6/14 Jesse Campbell hikeit@gmail.com

I am using the "application" and "application_java" cookbooks, which
include_recipe "tomcat" in the LWRP, and i've brought the same code over to
an new cookbook for tomeeplus.

include_recipe is working fine if I only run the LWRP precisely one time.
if i run the LWRP more than one time, the include_recipe gets ignored.

this sounds like the same as the OP's issue.
I can't (easily) change the "base" cookbook, because the base cookbook is
"application"

On Thu, May 30, 2013 at 8:22 AM, Dorian Jaminais <
dorian.jaminais@perfect-memory.com> wrote:

Thank you all for your responses.

@peter : run_context.include_recipe works but only if the LWRP is called
once in during the chef_run.

I have included a recipe that installs all the dependencies for the LWRP
to work.
This works perfectly, even if still I don't understand why I had this
strange behavior with run_context.include_recipe

2013/5/30 Peter Donald peter@realityforge.org

Hi,

On Thu, May 30, 2013 at 8:43 AM, Daniel DeLeo dan@kallistec.com wrote:

Bringing this back to the OP's issue, I think including a recipe (the
normal
way) to install prerequisites of a LWRP is the right way to go about
it. If
you are doing wizardry with chef internals, either 1) you're making
something more complicated than it should be, 2) chef is making
something
more complicated than it should be, or 3) you're a wizard. So far, I'm
inclined to think that including recipes from a provider falls into
category
#1, since you can just as easily and elegantly solve the problem with
a role
(or role cookbook if that's your thing). Am I missing something?

I think it is more useful to see it as a failure of chef rather than a
failure of the user. i.e. Option 2.

In my mind LWRPs are a mechanism for creating composable
abstractions. Anything you can do in a recipe should be possible to do
in a LWRP. Where this is not true I would consider it a bug.

For this specific scenario I can easily see a use for it. In our
environment, many of our recipes are data driven. Data is collected
from search + rules + external systems (ldap/db etc) and then this is
interpreted and resources defined based on the data. So often we will
not know which LWRPs will be active (and thus which precursor recipes
should be included) until the data is interpreted.

That said I thought include_recipe worked from within LWRPs...

--
Cheers,

Peter Donald

--
Dorian JAMINAIS
System Administrator
+33 6 95 10 95 37
http://perfect-memory.com

https://twitter.com/semanticbushttp://www.facebook.com/pages/Perfect-Memory/155555567821817

--
Dorian JAMINAIS
System Administrator
+33 6 95 10 95 37
http://perfect-memory.com

https://twitter.com/semanticbushttp://www.facebook.com/pages/Perfect-Memory/155555567821817

On Sunday, June 16, 2013 at 5:34 AM, Dorian Jaminais wrote:

Indeed that is exactly the same issue I had been running into.

For now I use to proposed workaround to include all those recipes from another recipe.

Maybe I should open a ticket on that issue.

2013/6/14 Jesse Campbell <hikeit@gmail.com (mailto:hikeit@gmail.com)>

I am using the "application" and "application_java" cookbooks, which include_recipe "tomcat" in the LWRP, and i've brought the same code over to an new cookbook for tomeeplus.

include_recipe is working fine if I only run the LWRP precisely one time.
if i run the LWRP more than one time, the include_recipe gets ignored.
This is the intended behavior of include_recipe and I'm certain that lots of people depend on this behavior. If you need to run a set of resources with different parameters, LWRPs are the accepted way to do that.

The use cases presented earlier in this thread for using include recipe within a LWRP are still violations of single responsibility principle in my opinion, but regardless, they only depend on running a recipe once.

Of course, it's all just ruby, so you can whip something up with eval or by dipping into chef internals, but of course you're responsible for whatever dragons that summons.

--
Daniel DeLeo