# run\_context.include\_recipe in a recipe within a role

**URL:** <https://discourse.chef.io/t/run-context-include-recipe-in-a-recipe-within-a-role/4032>\
**Category:** Chef Infra (archive)\
**Created:** [May 29, 2013, 10:26am UTC](https://discourse.chef.io/t/run-context-include-recipe-in-a-recipe-within-a-role/4032 "2013-05-29T10:26:29Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dorian\_Jaminais](https://avatars.discourse-cdn.com/v4/letter/d/ce7236/32.png) [@Dorian\_Jaminais](https://discourse.chef.io/u/Dorian_Jaminais)\
**Post date:** [May 29, 2013, 10:26am UTC](https://discourse.chef.io/t/run-context-include-recipe-in-a-recipe-within-a-role/4032/1 "2013-05-29T10:26:29Z")

</div>

Hi everyone

I am having trouble with LWRP, include\_recipe and roles.

I have a LWRP that includes some cookbooks :  
run\_context.include\_recipe "git"  
run\_context.include\_recipe "internal-cookbook"  
run\_context.include\_recipe “build-essential”

The git cookbook is the one available at opscode.  
I use this recipe in a variety of other internal cookbooks.

Here is my problem : when I add the cookbooks that use the LWRP directly to  
a node’s run\_list, it works perfectly but when I add them via a role, git  
is not installed. It works for the two other recipes included in the LWRP  
but not for git.

In the logs I have :  
DEBUG: Loading Recipe git via include\_recipe  
DEBUG: Found recipe default in cookbook git  
and then it goes to the next cookbook without the expected  
INFO: Processing package[git] action install (base::default line 9)

I am running chef 11.4.4 on ubuntu 12.04 LTS

Do you guys have any ideas what is happening and how to solve this ?

–  
Dorian JAMINAIS  
_System Administrator_  
+33 6 95 10 95 37  
[http://perfect-memory.com](http://perfect-memory.com)

[https://twitter.com/semanticbus](https://twitter.com/semanticbus)[http://www.facebook.com/pages/Perfect-Memory/155555567821817](http://www.facebook.com/pages/Perfect-Memory/155555567821817)

---

<div class="post-metadata">

**Author:** ![Dorian\_Jaminais](https://avatars.discourse-cdn.com/v4/letter/d/ce7236/32.png) [@Dorian\_Jaminais](https://discourse.chef.io/u/Dorian_Jaminais)\
**Post date:** [May 29, 2013, 4:06pm UTC](https://discourse.chef.io/t/run-context-include-recipe-in-a-recipe-within-a-role/4032/2 "2013-05-29T16:06:52Z")

</div>

I am still tracking down my problem and I have some news.  
It appears that he problem is not specific to the git cookbook.  
Indeed it appears that all recipes included in a LWRP  
'run\_context.include\_recipe' is only really added to the run\_list if the  
LWRP is called once during the run\_list.

If the LWRP is called more than once, it tells me that the resource has  
already been added to the run\_list even if it has not.

Is this a known bug ? I am doing something wrong ?  
I am failing to find any clues using my google-fu so I am turning to your  
expertise.

2013/5/29 Dorian Jaminais [dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com)

> Hi everyone
> 
> I am having trouble with LWRP, include\_recipe and roles.
> 
> I have a LWRP that includes some cookbooks :  
> run\_context.include\_recipe "git"  
> run\_context.include\_recipe "internal-cookbook"  
> run\_context.include\_recipe "build-essential"
> 
> The git cookbook is the one available at opscode.  
> I use this recipe in a variety of other internal cookbooks.
> 
> Here is my problem : when I add the cookbooks that use the LWRP directly  
> to a node's run\_list, it works perfectly but when I add them via a role,  
> git is not installed. It works for the two other recipes included in the  
> LWRP but not for git.
> 
> In the logs I have :  
> DEBUG: Loading Recipe git via include\_recipe  
> DEBUG: Found recipe default in cookbook git  
> and then it goes to the next cookbook without the expected  
> INFO: Processing package[git] action install (base::default line 9)
> 
> I am running chef 11.4.4 on ubuntu 12.04 LTS
> 
> Do you guys have any ideas what is happening and how to solve this ?
> 
> --  
> Dorian JAMINAIS  
> _System Administrator_  
> +33 6 95 10 95 37  
> [http://perfect-memory.com](http://perfect-memory.com)
> 
> [https://twitter.com/semanticbus](https://twitter.com/semanticbus)[http://www.facebook.com/pages/Perfect-Memory/155555567821817](http://www.facebook.com/pages/Perfect-Memory/155555567821817)

--  
Dorian JAMINAIS  
_System Administrator_  
+33 6 95 10 95 37  
[http://perfect-memory.com](http://perfect-memory.com)

[https://twitter.com/semanticbus](https://twitter.com/semanticbus)[http://www.facebook.com/pages/Perfect-Memory/155555567821817](http://www.facebook.com/pages/Perfect-Memory/155555567821817)

---

<div class="post-metadata">

**Author:** ![kallistec](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/kallistec/32/23_2.png) [@kallistec](https://discourse.chef.io/u/kallistec)\
**Post date:** [May 29, 2013, 4:14pm UTC](https://discourse.chef.io/t/run-context-include-recipe-in-a-recipe-within-a-role/4032/3 "2013-05-29T16:14:29Z")

</div>

On Wednesday, May 29, 2013 at 9:06 AM, Dorian Jaminais wrote:

> I am still tracking down my problem and I have some news.  
> It appears that he problem is not specific to the git cookbook.  
> Indeed it appears that all recipes included in a LWRP 'run\_context.include\_recipe' is only really added to the run\_list if the LWRP is called once during the run\_list.
> 
> If the LWRP is called more than once, it tells me that the resource has already been added to the run\_list even if it has not.
> 
> Is this a known bug ? I am doing something wrong ?  
> I am failing to find any clues using my google-fu so I am turning to your expertise.
> 
> 2013/5/29 Dorian Jaminais \<[dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com) ([mailto:dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com))\>
> 
> > Hi everyone
> > 
> > I am having trouble with LWRP, include\_recipe and roles.
> > 
> > I have a LWRP that includes some cookbooks :  
> > run\_context.include\_recipe "git"  
> > run\_context.include\_recipe "internal-cookbook"  
> > run\_context.include\_recipe "build-essential"

This is a bit odd. Why does the LWRP do this instead of a recipe? Showing more code, log output, and explaining why you're doing things this way would help others to understand your issue better.

--  
Daniel DeLeo

---

<div class="post-metadata">

**Author:** ![Dorian\_Jaminais](https://avatars.discourse-cdn.com/v4/letter/d/ce7236/32.png) [@Dorian\_Jaminais](https://discourse.chef.io/u/Dorian_Jaminais)\
**Post date:** [May 29, 2013, 4:39pm UTC](https://discourse.chef.io/t/run-context-include-recipe-in-a-recipe-within-a-role/4032/4 "2013-05-29T16:39:30Z")

</div>

Okay

I am using a LWRP instead of a recipe because I want to deploy about 15  
applications that are very similar.  
All those applications have a dedicated cookbook but as the installation  
process is always the same work flow, I have factorized it into a LWRP.

The work flow is pretty simple : assert that installation dependencies are  
met, clone the repo, bundle install the needed gems.

I have attached my provider to this mail (which by the way is included in a  
cookbook named gios).

In each application's cookbook I use :  
gios\_installer NAME do  
name NAME  
repository GIT\_URI  
command "./bin/truc"  
version "master"  
action :install  
end

As stated in my previous emails, using the LWRP that way will include the  
recipes ruby, git, base::certificate, pm-openssh::rsa and  
pm-openssh::known\_hosts only if the LWRP is called exactly once in the  
run\_list.

Thanks for your help

2013/5/29 Daniel DeLeo [dan@kallistec.com](mailto:dan@kallistec.com)

> On Wednesday, May 29, 2013 at 9:06 AM, Dorian Jaminais wrote:
> 
> I am still tracking down my problem and I have some news.  
> It appears that he problem is not specific to the git cookbook.  
> Indeed it appears that all recipes included in a LWRP  
> 'run\_context.include\_recipe' is only really added to the run\_list if the  
> LWRP is called once during the run\_list.
> 
> If the LWRP is called more than once, it tells me that the resource has  
> already been added to the run\_list even if it has not.
> 
> Is this a known bug ? I am doing something wrong ?  
> I am failing to find any clues using my google-fu so I am turning to your  
> expertise.
> 
> 2013/5/29 Dorian Jaminais [dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com)
> 
> Hi everyone
> 
> I am having trouble with LWRP, include\_recipe and roles.
> 
> I have a LWRP that includes some cookbooks :  
> run\_context.include\_recipe "git"  
> run\_context.include\_recipe "internal-cookbook"  
> run\_context.include\_recipe "build-essential"
> 
> This is a bit odd. Why does the LWRP do this instead of a recipe? Showing  
> more code, log output, and explaining why you're doing things this way  
> would help others to understand your issue better.
> 
> --  
> Daniel DeLeo

--  
Dorian JAMINAIS  
_System Administrator_  
+33 6 95 10 95 37  
[http://perfect-memory.com](http://perfect-memory.com)

[https://twitter.com/semanticbus](https://twitter.com/semanticbus)[http://www.facebook.com/pages/Perfect-Memory/155555567821817](http://www.facebook.com/pages/Perfect-Memory/155555567821817)

---

<div class="post-metadata">

**Author:** ![John\_E\_Vincent\_lusis](https://avatars.discourse-cdn.com/v4/letter/j/c89c15/32.png) [@John\_E\_Vincent\_lusis](https://discourse.chef.io/u/John_E_Vincent_lusis)\
**Post date:** [May 29, 2013, 4:41pm UTC](https://discourse.chef.io/t/run-context-include-recipe-in-a-recipe-within-a-role/4032/5 "2013-05-29T16:41:38Z")

</div>

Is there a reason you wouldn't, however, just add the "include\_recipe"  
statements to the default recipe for the LWRP cookbook then? It's not  
uncommon to do that even for library cookbooks iirc and it gets around (I  
think) the issue you're describing.

On Wed, May 29, 2013 at 12:39 PM, Dorian Jaminais \<  
[dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com)\> wrote:

> Okay
> 
> I am using a LWRP instead of a recipe because I want to deploy about 15  
> applications that are very similar.  
> All those applications have a dedicated cookbook but as the installation  
> process is always the same work flow, I have factorized it into a LWRP.
> 
> The work flow is pretty simple : assert that installation dependencies are  
> met, clone the repo, bundle install the needed gems.
> 
> I have attached my provider to this mail (which by the way is included in  
> a cookbook named gios).
> 
> In each application's cookbook I use :  
> gios\_installer NAME do  
> name NAME  
> repository GIT\_URI  
> command "./bin/truc"  
> version "master"  
> action :install  
> end
> 
> As stated in my previous emails, using the LWRP that way will include the  
> recipes ruby, git, base::certificate, pm-openssh::rsa and  
> pm-openssh::known\_hosts only if the LWRP is called exactly once in the  
> run\_list.
> 
> Thanks for your help
> 
> 2013/5/29 Daniel DeLeo [dan@kallistec.com](mailto:dan@kallistec.com)
> 
> > On Wednesday, May 29, 2013 at 9:06 AM, Dorian Jaminais wrote:
> > 
> > I am still tracking down my problem and I have some news.  
> > It appears that he problem is not specific to the git cookbook.  
> > Indeed it appears that all recipes included in a LWRP  
> > 'run\_context.include\_recipe' is only really added to the run\_list if the  
> > LWRP is called once during the run\_list.
> > 
> > If the LWRP is called more than once, it tells me that the resource has  
> > already been added to the run\_list even if it has not.
> > 
> > Is this a known bug ? I am doing something wrong ?  
> > I am failing to find any clues using my google-fu so I am turning to your  
> > expertise.
> > 
> > 2013/5/29 Dorian Jaminais [dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com)
> > 
> > Hi everyone
> > 
> > I am having trouble with LWRP, include\_recipe and roles.
> > 
> > I have a LWRP that includes some cookbooks :  
> > run\_context.include\_recipe "git"  
> > run\_context.include\_recipe "internal-cookbook"  
> > run\_context.include\_recipe "build-essential"
> > 
> > This is a bit odd. Why does the LWRP do this instead of a recipe? Showing  
> > more code, log output, and explaining why you're doing things this way  
> > would help others to understand your issue better.
> > 
> > --  
> > Daniel DeLeo
> 
> --  
> Dorian JAMINAIS  
> _System Administrator_  
> +33 6 95 10 95 37  
> [http://perfect-memory.com](http://perfect-memory.com)
> 
> [https://twitter.com/semanticbus](https://twitter.com/semanticbus)[http://www.facebook.com/pages/Perfect-Memory/155555567821817](http://www.facebook.com/pages/Perfect-Memory/155555567821817)

---

<div class="post-metadata">

**Author:** ![Dorian\_Jaminais](https://avatars.discourse-cdn.com/v4/letter/d/ce7236/32.png) [@Dorian\_Jaminais](https://discourse.chef.io/u/Dorian_Jaminais)\
**Post date:** [May 29, 2013, 4:46pm UTC](https://discourse.chef.io/t/run-context-include-recipe-in-a-recipe-within-a-role/4032/6 "2013-05-29T16:46:52Z")

</div>

Yes this can be a workaround, still I don't think the behavior I am getting  
is normal (and don't understand why) and I'd prefer to find a cleaner way  
than having to add a recipe just to include other recipes whereas it should  
be the task of my LWRP.

2013/5/29 John E. Vincent (lusis) [lusis.org+chef-list@gmail.com](mailto:lusis.org+chef-list@gmail.com)

> Is there a reason you wouldn't, however, just add the "include\_recipe"  
> statements to the default recipe for the LWRP cookbook then? It's not  
> uncommon to do that even for library cookbooks iirc and it gets around (I  
> think) the issue you're describing.
> 
> On Wed, May 29, 2013 at 12:39 PM, Dorian Jaminais \<  
> [dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com)\> wrote:
> 
> > Okay
> > 
> > I am using a LWRP instead of a recipe because I want to deploy about 15  
> > applications that are very similar.  
> > All those applications have a dedicated cookbook but as the installation  
> > process is always the same work flow, I have factorized it into a LWRP.
> > 
> > The work flow is pretty simple : assert that installation dependencies  
> > are met, clone the repo, bundle install the needed gems.
> > 
> > I have attached my provider to this mail (which by the way is included in  
> > a cookbook named gios).
> > 
> > In each application's cookbook I use :  
> > gios\_installer NAME do  
> > name NAME  
> > repository GIT\_URI  
> > command "./bin/truc"  
> > version "master"  
> > action :install  
> > end
> > 
> > As stated in my previous emails, using the LWRP that way will include the  
> > recipes ruby, git, base::certificate, pm-openssh::rsa and  
> > pm-openssh::known\_hosts only if the LWRP is called exactly once in the  
> > run\_list.
> > 
> > Thanks for your help
> > 
> > 2013/5/29 Daniel DeLeo [dan@kallistec.com](mailto:dan@kallistec.com)
> > 
> > > On Wednesday, May 29, 2013 at 9:06 AM, Dorian Jaminais wrote:
> > > 
> > > I am still tracking down my problem and I have some news.  
> > > It appears that he problem is not specific to the git cookbook.  
> > > Indeed it appears that all recipes included in a LWRP  
> > > 'run\_context.include\_recipe' is only really added to the run\_list if the  
> > > LWRP is called once during the run\_list.
> > > 
> > > If the LWRP is called more than once, it tells me that the resource has  
> > > already been added to the run\_list even if it has not.
> > > 
> > > Is this a known bug ? I am doing something wrong ?  
> > > I am failing to find any clues using my google-fu so I am turning to  
> > > your expertise.
> > > 
> > > 2013/5/29 Dorian Jaminais [dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com)
> > > 
> > > Hi everyone
> > > 
> > > I am having trouble with LWRP, include\_recipe and roles.
> > > 
> > > I have a LWRP that includes some cookbooks :  
> > > run\_context.include\_recipe "git"  
> > > run\_context.include\_recipe "internal-cookbook"  
> > > run\_context.include\_recipe "build-essential"
> > > 
> > > This is a bit odd. Why does the LWRP do this instead of a recipe?  
> > > Showing more code, log output, and explaining why you're doing things this  
> > > way would help others to understand your issue better.
> > > 
> > > --  
> > > Daniel DeLeo
> > 
> > --  
> > Dorian JAMINAIS  
> > _System Administrator_  
> > +33 6 95 10 95 37  
> > [http://perfect-memory.com](http://perfect-memory.com)
> > 
> > [https://twitter.com/semanticbus](https://twitter.com/semanticbus)[http://www.facebook.com/pages/Perfect-Memory/155555567821817](http://www.facebook.com/pages/Perfect-Memory/155555567821817)

--  
Dorian JAMINAIS  
_System Administrator_  
+33 6 95 10 95 37  
[http://perfect-memory.com](http://perfect-memory.com)

[https://twitter.com/semanticbus](https://twitter.com/semanticbus)[http://www.facebook.com/pages/Perfect-Memory/155555567821817](http://www.facebook.com/pages/Perfect-Memory/155555567821817)

---

<div class="post-metadata">

**Author:** ![John\_E\_Vincent\_lusis](https://avatars.discourse-cdn.com/v4/letter/j/c89c15/32.png) [@John\_E\_Vincent\_lusis](https://discourse.chef.io/u/John_E_Vincent_lusis)\
**Post date:** [May 29, 2013, 5:06pm UTC](https://discourse.chef.io/t/run-context-include-recipe-in-a-recipe-within-a-role/4032/7 "2013-05-29T17:06:42Z")

</div>

I think you misunderstand. You'll have to call include\_recipe to get access  
to the lwrp anyway. So adding the include\_recipe statements to "default.rb"  
for that lwrp cookbook doesn't require any additional work/change. They  
just get pulled in at the time the LWRP is included.

Unless I'm missing something obvious here.

On Wed, May 29, 2013 at 12:46 PM, Dorian Jaminais \<  
[dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com)\> wrote:

> Yes this can be a workaround, still I don't think the behavior I am  
> getting is normal (and don't understand why) and I'd prefer to find a  
> cleaner way than having to add a recipe just to include other recipes  
> whereas it should be the task of my LWRP.
> 
> 2013/5/29 John E. Vincent (lusis) [lusis.org+chef-list@gmail.com](mailto:lusis.org+chef-list@gmail.com)
> 
> Is there a reason you wouldn't, however, just add the "include\_recipe"
> 
> > statements to the default recipe for the LWRP cookbook then? It's not  
> > uncommon to do that even for library cookbooks iirc and it gets around (I  
> > think) the issue you're describing.
> > 
> > On Wed, May 29, 2013 at 12:39 PM, Dorian Jaminais \<  
> > [dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com)\> wrote:
> > 
> > > Okay
> > > 
> > > I am using a LWRP instead of a recipe because I want to deploy about 15  
> > > applications that are very similar.  
> > > All those applications have a dedicated cookbook but as the installation  
> > > process is always the same work flow, I have factorized it into a LWRP.
> > > 
> > > The work flow is pretty simple : assert that installation dependencies  
> > > are met, clone the repo, bundle install the needed gems.
> > > 
> > > I have attached my provider to this mail (which by the way is included  
> > > in a cookbook named gios).
> > > 
> > > In each application's cookbook I use :  
> > > gios\_installer NAME do  
> > > name NAME  
> > > repository GIT\_URI  
> > > command "./bin/truc"  
> > > version "master"  
> > > action :install  
> > > end
> > > 
> > > As stated in my previous emails, using the LWRP that way will include  
> > > the recipes ruby, git, base::certificate, pm-openssh::rsa and  
> > > pm-openssh::known\_hosts only if the LWRP is called exactly once in the  
> > > run\_list.
> > > 
> > > Thanks for your help
> > > 
> > > 2013/5/29 Daniel DeLeo [dan@kallistec.com](mailto:dan@kallistec.com)
> > > 
> > > > On Wednesday, May 29, 2013 at 9:06 AM, Dorian Jaminais wrote:
> > > > 
> > > > I am still tracking down my problem and I have some news.  
> > > > It appears that he problem is not specific to the git cookbook.  
> > > > Indeed it appears that all recipes included in a LWRP  
> > > > 'run\_context.include\_recipe' is only really added to the run\_list if the  
> > > > LWRP is called once during the run\_list.
> > > > 
> > > > If the LWRP is called more than once, it tells me that the resource has  
> > > > already been added to the run\_list even if it has not.
> > > > 
> > > > Is this a known bug ? I am doing something wrong ?  
> > > > I am failing to find any clues using my google-fu so I am turning to  
> > > > your expertise.
> > > > 
> > > > 2013/5/29 Dorian Jaminais [dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com)
> > > > 
> > > > Hi everyone
> > > > 
> > > > I am having trouble with LWRP, include\_recipe and roles.
> > > > 
> > > > I have a LWRP that includes some cookbooks :  
> > > > run\_context.include\_recipe "git"  
> > > > run\_context.include\_recipe "internal-cookbook"  
> > > > run\_context.include\_recipe "build-essential"
> > > > 
> > > > This is a bit odd. Why does the LWRP do this instead of a recipe?  
> > > > Showing more code, log output, and explaining why you're doing things this  
> > > > way would help others to understand your issue better.
> > > > 
> > > > --  
> > > > Daniel DeLeo
> > > 
> > > --  
> > > Dorian JAMINAIS  
> > > _System Administrator_  
> > > +33 6 95 10 95 37  
> > > [http://perfect-memory.com](http://perfect-memory.com)
> > > 
> > > [https://twitter.com/semanticbus](https://twitter.com/semanticbus)[http://www.facebook.com/pages/Perfect-Memory/155555567821817](http://www.facebook.com/pages/Perfect-Memory/155555567821817)
> 
> --  
> Dorian JAMINAIS  
> _System Administrator_  
> +33 6 95 10 95 37  
> [http://perfect-memory.com](http://perfect-memory.com)
> 
> [https://twitter.com/semanticbus](https://twitter.com/semanticbus)[http://www.facebook.com/pages/Perfect-Memory/155555567821817](http://www.facebook.com/pages/Perfect-Memory/155555567821817)

---

<div class="post-metadata">

**Author:** ![Ranjib](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/ranjib/32/1040_2.png) [@Ranjib](https://discourse.chef.io/u/Ranjib)\
**Post date:** [May 29, 2013, 5:07pm UTC](https://discourse.chef.io/t/run-context-include-recipe-in-a-recipe-within-a-role/4032/8 "2013-05-29T17:07:33Z")

</div>

i think its fine to include recipes via provider (or rather execute a whole  
recipe)

create a subcontext , and a mini chef run inside it, and converge the node.  
this is how we used to reuse existing chef resource inside an lwrp earlier..  
yfeldblum had a gist on it..

[http://realityforge.org/code/2012/07/17/lwrp-notify-on-changed-resources.html](http://realityforge.org/code/2012/07/17/lwrp-notify-on-changed-resources.html)

On Wed, May 29, 2013 at 9:46 AM, Dorian Jaminais \<  
[dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com)\> wrote:

> Yes this can be a workaround, still I don't think the behavior I am  
> getting is normal (and don't understand why) and I'd prefer to find a  
> cleaner way than having to add a recipe just to include other recipes  
> whereas it should be the task of my LWRP.
> 
> 2013/5/29 John E. Vincent (lusis) [lusis.org+chef-list@gmail.com](mailto:lusis.org+chef-list@gmail.com)
> 
> Is there a reason you wouldn't, however, just add the "include\_recipe"
> 
> > statements to the default recipe for the LWRP cookbook then? It's not  
> > uncommon to do that even for library cookbooks iirc and it gets around (I  
> > think) the issue you're describing.
> > 
> > On Wed, May 29, 2013 at 12:39 PM, Dorian Jaminais \<  
> > [dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com)\> wrote:
> > 
> > > Okay
> > > 
> > > I am using a LWRP instead of a recipe because I want to deploy about 15  
> > > applications that are very similar.  
> > > All those applications have a dedicated cookbook but as the installation  
> > > process is always the same work flow, I have factorized it into a LWRP.
> > > 
> > > The work flow is pretty simple : assert that installation dependencies  
> > > are met, clone the repo, bundle install the needed gems.
> > > 
> > > I have attached my provider to this mail (which by the way is included  
> > > in a cookbook named gios).
> > > 
> > > In each application's cookbook I use :  
> > > gios\_installer NAME do  
> > > name NAME  
> > > repository GIT\_URI  
> > > command "./bin/truc"  
> > > version "master"  
> > > action :install  
> > > end
> > > 
> > > As stated in my previous emails, using the LWRP that way will include  
> > > the recipes ruby, git, base::certificate, pm-openssh::rsa and  
> > > pm-openssh::known\_hosts only if the LWRP is called exactly once in the  
> > > run\_list.
> > > 
> > > Thanks for your help
> > > 
> > > 2013/5/29 Daniel DeLeo [dan@kallistec.com](mailto:dan@kallistec.com)
> > > 
> > > > On Wednesday, May 29, 2013 at 9:06 AM, Dorian Jaminais wrote:
> > > > 
> > > > I am still tracking down my problem and I have some news.  
> > > > It appears that he problem is not specific to the git cookbook.  
> > > > Indeed it appears that all recipes included in a LWRP  
> > > > 'run\_context.include\_recipe' is only really added to the run\_list if the  
> > > > LWRP is called once during the run\_list.
> > > > 
> > > > If the LWRP is called more than once, it tells me that the resource has  
> > > > already been added to the run\_list even if it has not.
> > > > 
> > > > Is this a known bug ? I am doing something wrong ?  
> > > > I am failing to find any clues using my google-fu so I am turning to  
> > > > your expertise.
> > > > 
> > > > 2013/5/29 Dorian Jaminais [dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com)
> > > > 
> > > > Hi everyone
> > > > 
> > > > I am having trouble with LWRP, include\_recipe and roles.
> > > > 
> > > > I have a LWRP that includes some cookbooks :  
> > > > run\_context.include\_recipe "git"  
> > > > run\_context.include\_recipe "internal-cookbook"  
> > > > run\_context.include\_recipe "build-essential"
> > > > 
> > > > This is a bit odd. Why does the LWRP do this instead of a recipe?  
> > > > Showing more code, log output, and explaining why you're doing things this  
> > > > way would help others to understand your issue better.
> > > > 
> > > > --  
> > > > Daniel DeLeo
> > > 
> > > --  
> > > Dorian JAMINAIS  
> > > _System Administrator_  
> > > +33 6 95 10 95 37  
> > > [http://perfect-memory.com](http://perfect-memory.com)
> > > 
> > > [https://twitter.com/semanticbus](https://twitter.com/semanticbus)[http://www.facebook.com/pages/Perfect-Memory/155555567821817](http://www.facebook.com/pages/Perfect-Memory/155555567821817)
> 
> --  
> Dorian JAMINAIS  
> _System Administrator_  
> +33 6 95 10 95 37  
> [http://perfect-memory.com](http://perfect-memory.com)
> 
> [https://twitter.com/semanticbus](https://twitter.com/semanticbus)[http://www.facebook.com/pages/Perfect-Memory/155555567821817](http://www.facebook.com/pages/Perfect-Memory/155555567821817)

---

<div class="post-metadata">

**Author:** ![sme](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/sme/32/271_2.png) [@sme](https://discourse.chef.io/u/sme)\
**Post date:** [May 29, 2013, 5:38pm UTC](https://discourse.chef.io/t/run-context-include-recipe-in-a-recipe-within-a-role/4032/9 "2013-05-29T17:38:04Z")

</div>

very neat.

Notifications from the lwrp are one thing, but IMO include\_recipe shouldn't  
need to be in the lwrp because as John mentioned the cookbook that provides  
the lwrp still needs to be included to make use of the specific lwrp and as  
such will run the default recipe. It should also result in a simpler lwrp.  
This seems easier to reason about as well since the lwrp is not the  
distribution mechanism for functionality, the cookbook is.

As Dan said though, we probably need to see more code to understand the  
full issue

On Wed, May 29, 2013 at 10:07 AM, Ranjib Dey [dey.ranjib@gmail.com](mailto:dey.ranjib@gmail.com) wrote:

> i think its fine to include recipes via provider (or rather execute a  
> whole recipe)
> 
> create a subcontext , and a mini chef run inside it, and converge the  
> node. this is how we used to reuse existing chef resource inside an lwrp  
> earlier..  
> yfeldblum had a gist on it..
> 
> [LWRP notifying on changed resources](http://realityforge.org/code/2012/07/17/lwrp-notify-on-changed-resources.html)
> 
> On Wed, May 29, 2013 at 9:46 AM, Dorian Jaminais \<  
> [dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com)\> wrote:
> 
> > Yes this can be a workaround, still I don't think the behavior I am  
> > getting is normal (and don't understand why) and I'd prefer to find a  
> > cleaner way than having to add a recipe just to include other recipes  
> > whereas it should be the task of my LWRP.
> > 
> > 2013/5/29 John E. Vincent (lusis) [lusis.org+chef-list@gmail.com](mailto:lusis.org+chef-list@gmail.com)
> > 
> > Is there a reason you wouldn't, however, just add the "include\_recipe"
> > 
> > > statements to the default recipe for the LWRP cookbook then? It's not  
> > > uncommon to do that even for library cookbooks iirc and it gets around (I  
> > > think) the issue you're describing.
> > > 
> > > On Wed, May 29, 2013 at 12:39 PM, Dorian Jaminais \<  
> > > [dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com)\> wrote:
> > > 
> > > > Okay
> > > > 
> > > > I am using a LWRP instead of a recipe because I want to deploy about 15  
> > > > applications that are very similar.  
> > > > All those applications have a dedicated cookbook but as the  
> > > > installation process is always the same work flow, I have factorized it  
> > > > into a LWRP.
> > > > 
> > > > The work flow is pretty simple : assert that installation dependencies  
> > > > are met, clone the repo, bundle install the needed gems.
> > > > 
> > > > I have attached my provider to this mail (which by the way is included  
> > > > in a cookbook named gios).
> > > > 
> > > > In each application's cookbook I use :  
> > > > gios\_installer NAME do  
> > > > name NAME  
> > > > repository GIT\_URI  
> > > > command "./bin/truc"  
> > > > version "master"  
> > > > action :install  
> > > > end
> > > > 
> > > > As stated in my previous emails, using the LWRP that way will include  
> > > > the recipes ruby, git, base::certificate, pm-openssh::rsa and  
> > > > pm-openssh::known\_hosts only if the LWRP is called exactly once in the  
> > > > run\_list.
> > > > 
> > > > Thanks for your help
> > > > 
> > > > 2013/5/29 Daniel DeLeo [dan@kallistec.com](mailto:dan@kallistec.com)
> > > > 
> > > > > On Wednesday, May 29, 2013 at 9:06 AM, Dorian Jaminais wrote:
> > > > > 
> > > > > I am still tracking down my problem and I have some news.  
> > > > > It appears that he problem is not specific to the git cookbook.  
> > > > > Indeed it appears that all recipes included in a LWRP  
> > > > > 'run\_context.include\_recipe' is only really added to the run\_list if the  
> > > > > LWRP is called once during the run\_list.
> > > > > 
> > > > > If the LWRP is called more than once, it tells me that the resource  
> > > > > has already been added to the run\_list even if it has not.
> > > > > 
> > > > > Is this a known bug ? I am doing something wrong ?  
> > > > > I am failing to find any clues using my google-fu so I am turning to  
> > > > > your expertise.
> > > > > 
> > > > > 2013/5/29 Dorian Jaminais [dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com)
> > > > > 
> > > > > Hi everyone
> > > > > 
> > > > > I am having trouble with LWRP, include\_recipe and roles.
> > > > > 
> > > > > I have a LWRP that includes some cookbooks :  
> > > > > run\_context.include\_recipe "git"  
> > > > > run\_context.include\_recipe "internal-cookbook"  
> > > > > run\_context.include\_recipe "build-essential"
> > > > > 
> > > > > This is a bit odd. Why does the LWRP do this instead of a recipe?  
> > > > > Showing more code, log output, and explaining why you're doing things this  
> > > > > way would help others to understand your issue better.
> > > > > 
> > > > > --  
> > > > > Daniel DeLeo
> > > > 
> > > > --  
> > > > Dorian JAMINAIS  
> > > > _System Administrator_  
> > > > +33 6 95 10 95 37  
> > > > [http://perfect-memory.com](http://perfect-memory.com)
> > > > 
> > > > [https://twitter.com/semanticbus](https://twitter.com/semanticbus)[http://www.facebook.com/pages/Perfect-Memory/155555567821817](http://www.facebook.com/pages/Perfect-Memory/155555567821817)
> > 
> > --  
> > Dorian JAMINAIS  
> > _System Administrator_  
> > +33 6 95 10 95 37  
> > [http://perfect-memory.com](http://perfect-memory.com)
> > 
> > [https://twitter.com/semanticbus](https://twitter.com/semanticbus)[http://www.facebook.com/pages/Perfect-Memory/155555567821817](http://www.facebook.com/pages/Perfect-Memory/155555567821817)

---

<div class="post-metadata">

**Author:** ![Ranjib](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/ranjib/32/1040_2.png) [@Ranjib](https://discourse.chef.io/u/Ranjib)\
**Post date:** [May 29, 2013, 5:39pm UTC](https://discourse.chef.io/t/run-context-include-recipe-in-a-recipe-within-a-role/4032/10 "2013-05-29T17:39:15Z")

</div>

try this

rc =run\_context.dup  
rc.resource\_collection = Chef::ResourceCollection.new  
rc.load\_recipe("foo::bar")  
Chef::Runner.new(rc).converge

.. for your case u'll be adding all the recipes,  
make sure u capture the updated resources. and set the  
new\_resource.updated\_by\_last\_action accordingly

On Wed, May 29, 2013 at 9:06 AM, Dorian Jaminais \<  
[dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com)\> wrote:

> I am still tracking down my problem and I have some news.  
> It appears that he problem is not specific to the git cookbook.  
> Indeed it appears that all recipes included in a LWRP  
> 'run\_context.include\_recipe' is only really added to the run\_list if the  
> LWRP is called once during the run\_list.
> 
> If the LWRP is called more than once, it tells me that the resource has  
> already been added to the run\_list even if it has not.
> 
> Is this a known bug ? I am doing something wrong ?  
> I am failing to find any clues using my google-fu so I am turning to your  
> expertise.
> 
> 2013/5/29 Dorian Jaminais [dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com)
> 
> > Hi everyone
> > 
> > I am having trouble with LWRP, include\_recipe and roles.
> > 
> > I have a LWRP that includes some cookbooks :  
> > run\_context.include\_recipe "git"  
> > run\_context.include\_recipe "internal-cookbook"  
> > run\_context.include\_recipe "build-essential"
> > 
> > The git cookbook is the one available at opscode.  
> > I use this recipe in a variety of other internal cookbooks.
> > 
> > Here is my problem : when I add the cookbooks that use the LWRP directly  
> > to a node's run\_list, it works perfectly but when I add them via a role,  
> > git is not installed. It works for the two other recipes included in the  
> > LWRP but not for git.
> > 
> > In the logs I have :  
> > DEBUG: Loading Recipe git via include\_recipe  
> > DEBUG: Found recipe default in cookbook git  
> > and then it goes to the next cookbook without the expected  
> > INFO: Processing package[git] action install (base::default line 9)
> > 
> > I am running chef 11.4.4 on ubuntu 12.04 LTS
> > 
> > Do you guys have any ideas what is happening and how to solve this ?
> > 
> > --  
> > Dorian JAMINAIS  
> > _System Administrator_  
> > +33 6 95 10 95 37  
> > [http://perfect-memory.com](http://perfect-memory.com)
> > 
> > [https://twitter.com/semanticbus](https://twitter.com/semanticbus)[http://www.facebook.com/pages/Perfect-Memory/155555567821817](http://www.facebook.com/pages/Perfect-Memory/155555567821817)
> 
> --  
> Dorian JAMINAIS  
> _System Administrator_  
> +33 6 95 10 95 37  
> [http://perfect-memory.com](http://perfect-memory.com)
> 
> [https://twitter.com/semanticbus](https://twitter.com/semanticbus)[http://www.facebook.com/pages/Perfect-Memory/155555567821817](http://www.facebook.com/pages/Perfect-Memory/155555567821817)

---

<div class="post-metadata">

**Author:** ![Sean\_OMeara](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/sean_omeara/32/435_2.png) [@Sean\_OMeara](https://discourse.chef.io/u/Sean_OMeara)\
**Post date:** [May 29, 2013, 5:43pm UTC](https://discourse.chef.io/t/run-context-include-recipe-in-a-recipe-within-a-role/4032/11 "2013-05-29T17:43:27Z")

</div>

Try sticking a "use\_inline\_resources" at the top of your LWRP file.  
It does that whole run\_context pattern to allow for notifications to work.  
I'm not sure if include\_recipe will work.  
-s

On Wed, May 29, 2013 at 1:39 PM, Ranjib Dey [dey.ranjib@gmail.com](mailto:dey.ranjib@gmail.com) wrote:

> try this
> 
> rc =run\_context.dup  
> rc.resource\_collection = Chef::ResourceCollection.new  
> rc.load\_recipe("foo::bar")  
> Chef::Runner.new(rc).converge
> 
> .. for your case u'll be adding all the recipes,  
> make sure u capture the updated resources. and set the  
> new\_resource.updated\_by\_last\_action accordingly
> 
> On Wed, May 29, 2013 at 9:06 AM, Dorian Jaminais \<  
> [dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com)\> wrote:
> 
> > I am still tracking down my problem and I have some news.  
> > It appears that he problem is not specific to the git cookbook.  
> > Indeed it appears that all recipes included in a LWRP  
> > 'run\_context.include\_recipe' is only really added to the run\_list if the  
> > LWRP is called once during the run\_list.
> > 
> > If the LWRP is called more than once, it tells me that the resource has  
> > already been added to the run\_list even if it has not.
> > 
> > Is this a known bug ? I am doing something wrong ?  
> > I am failing to find any clues using my google-fu so I am turning to your  
> > expertise.
> > 
> > 2013/5/29 Dorian Jaminais [dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com)
> > 
> > > Hi everyone
> > > 
> > > I am having trouble with LWRP, include\_recipe and roles.
> > > 
> > > I have a LWRP that includes some cookbooks :  
> > > run\_context.include\_recipe "git"  
> > > run\_context.include\_recipe "internal-cookbook"  
> > > run\_context.include\_recipe "build-essential"
> > > 
> > > The git cookbook is the one available at opscode.  
> > > I use this recipe in a variety of other internal cookbooks.
> > > 
> > > Here is my problem : when I add the cookbooks that use the LWRP directly  
> > > to a node's run\_list, it works perfectly but when I add them via a role,  
> > > git is not installed. It works for the two other recipes included in the  
> > > LWRP but not for git.
> > > 
> > > In the logs I have :  
> > > DEBUG: Loading Recipe git via include\_recipe  
> > > DEBUG: Found recipe default in cookbook git  
> > > and then it goes to the next cookbook without the expected  
> > > INFO: Processing package[git] action install (base::default line 9)
> > > 
> > > I am running chef 11.4.4 on ubuntu 12.04 LTS
> > > 
> > > Do you guys have any ideas what is happening and how to solve this ?
> > > 
> > > --  
> > > Dorian JAMINAIS  
> > > _System Administrator_  
> > > +33 6 95 10 95 37  
> > > [http://perfect-memory.com](http://perfect-memory.com)
> > > 
> > > [https://twitter.com/semanticbus](https://twitter.com/semanticbus)[http://www.facebook.com/pages/Perfect-Memory/155555567821817](http://www.facebook.com/pages/Perfect-Memory/155555567821817)
> > 
> > --  
> > Dorian JAMINAIS  
> > _System Administrator_  
> > +33 6 95 10 95 37  
> > [http://perfect-memory.com](http://perfect-memory.com)
> > 
> > [https://twitter.com/semanticbus](https://twitter.com/semanticbus)[http://www.facebook.com/pages/Perfect-Memory/155555567821817](http://www.facebook.com/pages/Perfect-Memory/155555567821817)

---

<div class="post-metadata">

**Author:** ![Ranjib](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/ranjib/32/1040_2.png) [@Ranjib](https://discourse.chef.io/u/Ranjib)\
**Post date:** [May 29, 2013, 5:45pm UTC](https://discourse.chef.io/t/run-context-include-recipe-in-a-recipe-within-a-role/4032/12 "2013-05-29T17:45:58Z")

</div>

i think both are fine, the non lwrp way. u'll be introducing the  
conditionals inside the recipe.. which will

1. reduce the declarativeness of the recipe
2. u'll be limited by the compile time info , in certain cases
3. testing will be harder

the lwrp opens up a much cleaner way to reuse this, brings the conditionals  
inside an abstraction, and also allows you to set your resource's update  
status depending upon the entire dependency (i.e. now you can say i was  
updated if any of the dependant resource were update), which you might  
exploit using notification mechanism is anywhere else... u'll lose most of  
this if you push these logic in the recipe...  
no?

On Wed, May 29, 2013 at 10:38 AM, Sean Escriva [sean.escriva@gmail.com](mailto:sean.escriva@gmail.com)wrote:

> very neat.
> 
> Notifications from the lwrp are one thing, but IMO include\_recipe  
> shouldn't need to be in the lwrp because as John mentioned the cookbook  
> that provides the lwrp still needs to be included to make use of the  
> specific lwrp and as such will run the default recipe. It should also  
> result in a simpler lwrp. This seems easier to reason about as well since  
> the lwrp is not the distribution mechanism for functionality, the cookbook  
> is.
> 
> As Dan said though, we probably need to see more code to understand the  
> full issue
> 
> On Wed, May 29, 2013 at 10:07 AM, Ranjib Dey [dey.ranjib@gmail.com](mailto:dey.ranjib@gmail.com) wrote:
> 
> > i think its fine to include recipes via provider (or rather execute a  
> > whole recipe)
> > 
> > create a subcontext , and a mini chef run inside it, and converge the  
> > node. this is how we used to reuse existing chef resource inside an lwrp  
> > earlier..  
> > yfeldblum had a gist on it..
> > 
> > [LWRP notifying on changed resources](http://realityforge.org/code/2012/07/17/lwrp-notify-on-changed-resources.html)
> > 
> > On Wed, May 29, 2013 at 9:46 AM, Dorian Jaminais \<  
> > [dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com)\> wrote:
> > 
> > > Yes this can be a workaround, still I don't think the behavior I am  
> > > getting is normal (and don't understand why) and I'd prefer to find a  
> > > cleaner way than having to add a recipe just to include other recipes  
> > > whereas it should be the task of my LWRP.
> > > 
> > > 2013/5/29 John E. Vincent (lusis) [lusis.org+chef-list@gmail.com](mailto:lusis.org+chef-list@gmail.com)
> > > 
> > > Is there a reason you wouldn't, however, just add the "include\_recipe"
> > > 
> > > > statements to the default recipe for the LWRP cookbook then? It's not  
> > > > uncommon to do that even for library cookbooks iirc and it gets around (I  
> > > > think) the issue you're describing.
> > > > 
> > > > On Wed, May 29, 2013 at 12:39 PM, Dorian Jaminais \<  
> > > > [dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com)\> wrote:
> > > > 
> > > > > Okay
> > > > > 
> > > > > I am using a LWRP instead of a recipe because I want to deploy about  
> > > > > 15 applications that are very similar.  
> > > > > All those applications have a dedicated cookbook but as the  
> > > > > installation process is always the same work flow, I have factorized it  
> > > > > into a LWRP.
> > > > > 
> > > > > The work flow is pretty simple : assert that installation dependencies  
> > > > > are met, clone the repo, bundle install the needed gems.
> > > > > 
> > > > > I have attached my provider to this mail (which by the way is included  
> > > > > in a cookbook named gios).
> > > > > 
> > > > > In each application's cookbook I use :  
> > > > > gios\_installer NAME do  
> > > > > name NAME  
> > > > > repository GIT\_URI  
> > > > > command "./bin/truc"  
> > > > > version "master"  
> > > > > action :install  
> > > > > end
> > > > > 
> > > > > As stated in my previous emails, using the LWRP that way will include  
> > > > > the recipes ruby, git, base::certificate, pm-openssh::rsa and  
> > > > > pm-openssh::known\_hosts only if the LWRP is called exactly once in the  
> > > > > run\_list.
> > > > > 
> > > > > Thanks for your help
> > > > > 
> > > > > 2013/5/29 Daniel DeLeo [dan@kallistec.com](mailto:dan@kallistec.com)
> > > > > 
> > > > > > On Wednesday, May 29, 2013 at 9:06 AM, Dorian Jaminais wrote:
> > > > > > 
> > > > > > I am still tracking down my problem and I have some news.  
> > > > > > It appears that he problem is not specific to the git cookbook.  
> > > > > > Indeed it appears that all recipes included in a LWRP  
> > > > > > 'run\_context.include\_recipe' is only really added to the run\_list if the  
> > > > > > LWRP is called once during the run\_list.
> > > > > > 
> > > > > > If the LWRP is called more than once, it tells me that the resource  
> > > > > > has already been added to the run\_list even if it has not.
> > > > > > 
> > > > > > Is this a known bug ? I am doing something wrong ?  
> > > > > > I am failing to find any clues using my google-fu so I am turning to  
> > > > > > your expertise.
> > > > > > 
> > > > > > 2013/5/29 Dorian Jaminais [dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com)
> > > > > > 
> > > > > > Hi everyone
> > > > > > 
> > > > > > I am having trouble with LWRP, include\_recipe and roles.
> > > > > > 
> > > > > > I have a LWRP that includes some cookbooks :  
> > > > > > run\_context.include\_recipe "git"  
> > > > > > run\_context.include\_recipe "internal-cookbook"  
> > > > > > run\_context.include\_recipe "build-essential"
> > > > > > 
> > > > > > This is a bit odd. Why does the LWRP do this instead of a recipe?  
> > > > > > Showing more code, log output, and explaining why you're doing things this  
> > > > > > way would help others to understand your issue better.
> > > > > > 
> > > > > > --  
> > > > > > Daniel DeLeo
> > > > > 
> > > > > --  
> > > > > Dorian JAMINAIS  
> > > > > _System Administrator_  
> > > > > +33 6 95 10 95 37  
> > > > > [http://perfect-memory.com](http://perfect-memory.com)
> > > > > 
> > > > > [https://twitter.com/semanticbus](https://twitter.com/semanticbus)[http://www.facebook.com/pages/Perfect-Memory/155555567821817](http://www.facebook.com/pages/Perfect-Memory/155555567821817)
> > > 
> > > --  
> > > Dorian JAMINAIS  
> > > _System Administrator_  
> > > +33 6 95 10 95 37  
> > > [http://perfect-memory.com](http://perfect-memory.com)
> > > 
> > > [https://twitter.com/semanticbus](https://twitter.com/semanticbus)[http://www.facebook.com/pages/Perfect-Memory/155555567821817](http://www.facebook.com/pages/Perfect-Memory/155555567821817)

---

<div class="post-metadata">

**Author:** ![Cassiano\_Leal](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/cassiano_leal/32/86_2.png) [@Cassiano\_Leal](https://discourse.chef.io/u/Cassiano_Leal)\
**Post date:** [May 29, 2013, 6:00pm UTC](https://discourse.chef.io/t/run-context-include-recipe-in-a-recipe-within-a-role/4032/13 "2013-05-29T18:00:11Z")

</div>

Just to understand better, do I actually need to include a library cookbook's recipe in the run\_list of a node in order to use its LWRPs?

I remember a thread not long ago in this mailing list about "how to test library cookbooks without recipes" or something like that, and someone specifically mentioned that requiring the lib cookbook in the metadata file would be enough.

Just checking. 🙂

- cassiano

On Wednesday, May 29, 2013 at 14:45, Ranjib Dey wrote:

> i think both are fine, the non lwrp way. u'll be introducing the conditionals inside the recipe.. which will
> 
> 1. reduce the declarativeness of the recipe
> 2. u'll be limited by the compile time info , in certain cases
> 3. testing will be harder
> 
> the lwrp opens up a much cleaner way to reuse this, brings the conditionals inside an abstraction, and also allows you to set your resource's update status depending upon the entire dependency (i.e. now you can say i was updated if any of the dependant resource were update), which you might exploit using notification mechanism is anywhere else... u'll lose most of this if you push these logic in the recipe...  
> no?
> 
> On Wed, May 29, 2013 at 10:38 AM, Sean Escriva \<[sean.escriva@gmail.com](mailto:sean.escriva@gmail.com) ([mailto:sean.escriva@gmail.com](mailto:sean.escriva@gmail.com))\> wrote:
> 
> > very neat.
> > 
> > Notifications from the lwrp are one thing, but IMO include\_recipe shouldn't need to be in the lwrp because as John mentioned the cookbook that provides the lwrp still needs to be included to make use of the specific lwrp and as such will run the default recipe. It should also result in a simpler lwrp. This seems easier to reason about as well since the lwrp is not the distribution mechanism for functionality, the cookbook is.
> > 
> > As Dan said though, we probably need to see more code to understand the full issue
> > 
> > On Wed, May 29, 2013 at 10:07 AM, Ranjib Dey \<[dey.ranjib@gmail.com](mailto:dey.ranjib@gmail.com) ([mailto:dey.ranjib@gmail.com](mailto:dey.ranjib@gmail.com))\> wrote:
> > 
> > > i think its fine to include recipes via provider (or rather execute a whole recipe)
> > > 
> > > create a subcontext , and a mini chef run inside it, and converge the node. this is how we used to reuse existing chef resource inside an lwrp earlier..  
> > > yfeldblum had a gist on it..
> > > 
> > > [LWRP notifying on changed resources](http://realityforge.org/code/2012/07/17/lwrp-notify-on-changed-resources.html)
> > > 
> > > On Wed, May 29, 2013 at 9:46 AM, Dorian Jaminais \<[dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com) ([mailto:dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com))\> wrote:
> > > 
> > > > Yes this can be a workaround, still I don't think the behavior I am getting is normal (and don't understand why) and I'd prefer to find a cleaner way than having to add a recipe just to include other recipes whereas it should be the task of my LWRP.
> > > > 
> > > > 2013/5/29 John E. Vincent (lusis) \<[lusis.org+chef-list@gmail.com](mailto:lusis.org+chef-list@gmail.com) ([mailto:lusis.org+chef-list@gmail.com](mailto:lusis.org+chef-list@gmail.com))\>
> > > > 
> > > > > Is there a reason you wouldn't, however, just add the "include\_recipe" statements to the default recipe for the LWRP cookbook then? It's not uncommon to do that even for library cookbooks iirc and it gets around (I think) the issue you're describing.
> > > > > 
> > > > > On Wed, May 29, 2013 at 12:39 PM, Dorian Jaminais \<[dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com) ([mailto:dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com))\> wrote:
> > > > > 
> > > > > > Okay
> > > > > > 
> > > > > > I am using a LWRP instead of a recipe because I want to deploy about 15 applications that are very similar.  
> > > > > > All those applications have a dedicated cookbook but as the installation process is always the same work flow, I have factorized it into a LWRP.
> > > > > > 
> > > > > > The work flow is pretty simple : assert that installation dependencies are met, clone the repo, bundle install the needed gems.
> > > > > > 
> > > > > > I have attached my provider to this mail (which by the way is included in a cookbook named gios).
> > > > > > 
> > > > > > In each application's cookbook I use :  
> > > > > > gios\_installer NAME do  
> > > > > > name NAME  
> > > > > > repository GIT\_URI  
> > > > > > command "./bin/truc"  
> > > > > > version "master"  
> > > > > > action :install  
> > > > > > end
> > > > > > 
> > > > > > As stated in my previous emails, using the LWRP that way will include the recipes ruby, git, base::certificate, pm-openssh::rsa and pm-openssh::known\_hosts only if the LWRP is called exactly once in the run\_list.
> > > > > > 
> > > > > > Thanks for your help
> > > > > > 
> > > > > > 2013/5/29 Daniel DeLeo \<[dan@kallistec.com](mailto:dan@kallistec.com) ([mailto:dan@kallistec.com](mailto:dan@kallistec.com))\>
> > > > > > 
> > > > > > > On Wednesday, May 29, 2013 at 9:06 AM, Dorian Jaminais wrote:
> > > > > > > 
> > > > > > > > I am still tracking down my problem and I have some news.  
> > > > > > > > It appears that he problem is not specific to the git cookbook.  
> > > > > > > > Indeed it appears that all recipes included in a LWRP 'run\_context.include\_recipe' is only really added to the run\_list if the LWRP is called once during the run\_list.
> > > > > > > > 
> > > > > > > > If the LWRP is called more than once, it tells me that the resource has already been added to the run\_list even if it has not.
> > > > > > > > 
> > > > > > > > Is this a known bug ? I am doing something wrong ?  
> > > > > > > > I am failing to find any clues using my google-fu so I am turning to your expertise.
> > > > > > > > 
> > > > > > > > 2013/5/29 Dorian Jaminais \<[dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com) ([mailto:dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com))\>
> > > > > > > > 
> > > > > > > > > Hi everyone
> > > > > > > > > 
> > > > > > > > > I am having trouble with LWRP, include\_recipe and roles.
> > > > > > > > > 
> > > > > > > > > I have a LWRP that includes some cookbooks :  
> > > > > > > > > run\_context.include\_recipe "git"  
> > > > > > > > > run\_context.include\_recipe "internal-cookbook"  
> > > > > > > > > run\_context.include\_recipe "build-essential"
> > > > > > > 
> > > > > > > This is a bit odd. Why does the LWRP do this instead of a recipe? Showing more code, log output, and explaining why you're doing things this way would help others to understand your issue better.
> > > > > > > 
> > > > > > > --  
> > > > > > > Daniel DeLeo
> > > > > > 
> > > > > > --  
> > > > > > Dorian JAMINAIS  
> > > > > > System Administrator  
> > > > > > +33 6 95 10 95 37 (tel:%2B33%206%2095%2010%2095%2037)
> > > > 
> > > > --  
> > > > Dorian JAMINAIS  
> > > > System Administrator  
> > > > +33 6 95 10 95 37

---

<div class="post-metadata">

**Author:** ![Ranjib](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/ranjib/32/1040_2.png) [@Ranjib](https://discourse.chef.io/u/Ranjib)\
**Post date:** [May 29, 2013, 6:58pm UTC](https://discourse.chef.io/t/run-context-include-recipe-in-a-recipe-within-a-role/4032/14 "2013-05-29T18:58:19Z")

</div>

no.. you dont have to.. the libraries and lwrps are available just by  
declaring the dependency, u dont have to include the parent cookbook's  
default or any other recipe.

On Wed, May 29, 2013 at 11:00 AM, Cassiano Leal [cassianoleal@gmail.com](mailto:cassianoleal@gmail.com)wrote:

> Just to understand better, do I actually need to include a library  
> cookbook's recipe in the run\_list of a node in order to use its LWRPs?
> 
> I remember a thread not long ago in this mailing list about "how to test  
> library cookbooks without recipes" or something like that, and someone  
> specifically mentioned that requiring the lib cookbook in the metadata file  
> would be enough.
> 
> Just checking. 🙂
> 
> - cassiano
> 
> On Wednesday, May 29, 2013 at 14:45, Ranjib Dey wrote:
> 
> i think both are fine, the non lwrp way. u'll be introducing the  
> conditionals inside the recipe.. which will
> 
> 1. reduce the declarativeness of the recipe
> 2. u'll be limited by the compile time info , in certain cases
> 3. testing will be harder
> 
> the lwrp opens up a much cleaner way to reuse this, brings the  
> conditionals inside an abstraction, and also allows you to set your  
> resource's update status depending upon the entire dependency (i.e. now you  
> can say i was updated if any of the dependant resource were update), which  
> you might exploit using notification mechanism is anywhere else... u'll  
> lose most of this if you push these logic in the recipe...  
> no?
> 
> On Wed, May 29, 2013 at 10:38 AM, Sean Escriva [sean.escriva@gmail.com](mailto:sean.escriva@gmail.com)wrote:
> 
> very neat.
> 
> Notifications from the lwrp are one thing, but IMO include\_recipe  
> shouldn't need to be in the lwrp because as John mentioned the cookbook  
> that provides the lwrp still needs to be included to make use of the  
> specific lwrp and as such will run the default recipe. It should also  
> result in a simpler lwrp. This seems easier to reason about as well since  
> the lwrp is not the distribution mechanism for functionality, the cookbook  
> is.
> 
> As Dan said though, we probably need to see more code to understand the  
> full issue
> 
> On Wed, May 29, 2013 at 10:07 AM, Ranjib Dey [dey.ranjib@gmail.com](mailto:dey.ranjib@gmail.com) wrote:
> 
> i think its fine to include recipes via provider (or rather execute a  
> whole recipe)
> 
> create a subcontext , and a mini chef run inside it, and converge the  
> node. this is how we used to reuse existing chef resource inside an lwrp  
> earlier..  
> yfeldblum had a gist on it..
> 
> [LWRP notifying on changed resources](http://realityforge.org/code/2012/07/17/lwrp-notify-on-changed-resources.html)
> 
> On Wed, May 29, 2013 at 9:46 AM, Dorian Jaminais \<  
> [dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com)\> wrote:
> 
> Yes this can be a workaround, still I don't think the behavior I am  
> getting is normal (and don't understand why) and I'd prefer to find a  
> cleaner way than having to add a recipe just to include other recipes  
> whereas it should be the task of my LWRP.
> 
> 2013/5/29 John E. Vincent (lusis) [lusis.org+chef-list@gmail.com](mailto:lusis.org+chef-list@gmail.com)
> 
> Is there a reason you wouldn't, however, just add the "include\_recipe"  
> statements to the default recipe for the LWRP cookbook then? It's not  
> uncommon to do that even for library cookbooks iirc and it gets around (I  
> think) the issue you're describing.
> 
> On Wed, May 29, 2013 at 12:39 PM, Dorian Jaminais \<  
> [dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com)\> wrote:
> 
> Okay
> 
> I am using a LWRP instead of a recipe because I want to deploy about 15  
> applications that are very similar.  
> All those applications have a dedicated cookbook but as the installation  
> process is always the same work flow, I have factorized it into a LWRP.
> 
> The work flow is pretty simple : assert that installation dependencies are  
> met, clone the repo, bundle install the needed gems.
> 
> I have attached my provider to this mail (which by the way is included in  
> a cookbook named gios).
> 
> In each application's cookbook I use :  
> gios\_installer NAME do  
> name NAME  
> repository GIT\_URI  
> command "./bin/truc"  
> version "master"  
> action :install  
> end
> 
> As stated in my previous emails, using the LWRP that way will include the  
> recipes ruby, git, base::certificate, pm-openssh::rsa and  
> pm-openssh::known\_hosts only if the LWRP is called exactly once in the  
> run\_list.
> 
> Thanks for your help
> 
> 2013/5/29 Daniel DeLeo [dan@kallistec.com](mailto:dan@kallistec.com)
> 
> On Wednesday, May 29, 2013 at 9:06 AM, Dorian Jaminais wrote:
> 
> I am still tracking down my problem and I have some news.  
> It appears that he problem is not specific to the git cookbook.  
> Indeed it appears that all recipes included in a LWRP  
> 'run\_context.include\_recipe' is only really added to the run\_list if the  
> LWRP is called once during the run\_list.
> 
> If the LWRP is called more than once, it tells me that the resource has  
> already been added to the run\_list even if it has not.
> 
> Is this a known bug ? I am doing something wrong ?  
> I am failing to find any clues using my google-fu so I am turning to your  
> expertise.
> 
> 2013/5/29 Dorian Jaminais [dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com)
> 
> Hi everyone
> 
> I am having trouble with LWRP, include\_recipe and roles.
> 
> I have a LWRP that includes some cookbooks :  
> run\_context.include\_recipe "git"  
> run\_context.include\_recipe "internal-cookbook"  
> run\_context.include\_recipe "build-essential"
> 
> This is a bit odd. Why does the LWRP do this instead of a recipe? Showing  
> more code, log output, and explaining why you're doing things this way  
> would help others to understand your issue better.
> 
> --  
> Daniel DeLeo
> 
> --  
> Dorian JAMINAIS  
> _System Administrator_  
> +33 6 95 10 95 37  
> [http://perfect-memory.com](http://perfect-memory.com)
> 
> [https://twitter.com/semanticbus](https://twitter.com/semanticbus)[http://www.facebook.com/pages/Perfect-Memory/155555567821817](http://www.facebook.com/pages/Perfect-Memory/155555567821817)
> 
> --  
> Dorian JAMINAIS  
> _System Administrator_  
> +33 6 95 10 95 37  
> [http://perfect-memory.com](http://perfect-memory.com)
> 
> [https://twitter.com/semanticbus](https://twitter.com/semanticbus)[http://www.facebook.com/pages/Perfect-Memory/155555567821817](http://www.facebook.com/pages/Perfect-Memory/155555567821817)

---

<div class="post-metadata">

**Author:** ![John\_E\_Vincent\_lusis](https://avatars.discourse-cdn.com/v4/letter/j/c89c15/32.png) [@John\_E\_Vincent\_lusis](https://discourse.chef.io/u/John_E_Vincent_lusis)\
**Post date:** [May 29, 2013, 7:07pm UTC](https://discourse.chef.io/t/run-context-include-recipe-in-a-recipe-within-a-role/4032/15 "2013-05-29T19:07:25Z")

</div>

I'm still confused by this. The windows and runit resources, as an example,  
are not available to a recipe unless include\_recipe is used at the top.  
They've always failed for me otherwise (regardless of including the  
dependency in metadata.rb). I never bothered to revisit if this was a bug  
and I've always done include\_recipe "runit" (or any recipe for that matter)  
where I needed the resources from that LWRP in the recipe itself.

I'm totally willing to admit I've been wrong all this time but there was a  
reason I did it at one point and it fixed the problem at the time. I just  
never went back and challenged that assumption.

On Wed, May 29, 2013 at 2:58 PM, Ranjib Dey [dey.ranjib@gmail.com](mailto:dey.ranjib@gmail.com) wrote:

> no.. you dont have to.. the libraries and lwrps are available just by  
> declaring the dependency, u dont have to include the parent cookbook's  
> default or any other recipe.
> 
> On Wed, May 29, 2013 at 11:00 AM, Cassiano Leal [cassianoleal@gmail.com](mailto:cassianoleal@gmail.com)wrote:
> 
> > Just to understand better, do I actually need to include a library  
> > cookbook's recipe in the run\_list of a node in order to use its LWRPs?
> > 
> > I remember a thread not long ago in this mailing list about "how to test  
> > library cookbooks without recipes" or something like that, and someone  
> > specifically mentioned that requiring the lib cookbook in the metadata file  
> > would be enough.
> > 
> > Just checking. 🙂
> > 
> > - cassiano
> > 
> > On Wednesday, May 29, 2013 at 14:45, Ranjib Dey wrote:
> > 
> > i think both are fine, the non lwrp way. u'll be introducing the  
> > conditionals inside the recipe.. which will
> > 
> > 1. reduce the declarativeness of the recipe
> > 2. u'll be limited by the compile time info , in certain cases
> > 3. testing will be harder
> > 
> > the lwrp opens up a much cleaner way to reuse this, brings the  
> > conditionals inside an abstraction, and also allows you to set your  
> > resource's update status depending upon the entire dependency (i.e. now you  
> > can say i was updated if any of the dependant resource were update), which  
> > you might exploit using notification mechanism is anywhere else... u'll  
> > lose most of this if you push these logic in the recipe...  
> > no?
> > 
> > On Wed, May 29, 2013 at 10:38 AM, Sean Escriva [sean.escriva@gmail.com](mailto:sean.escriva@gmail.com)wrote:
> > 
> > very neat.
> > 
> > Notifications from the lwrp are one thing, but IMO include\_recipe  
> > shouldn't need to be in the lwrp because as John mentioned the cookbook  
> > that provides the lwrp still needs to be included to make use of the  
> > specific lwrp and as such will run the default recipe. It should also  
> > result in a simpler lwrp. This seems easier to reason about as well since  
> > the lwrp is not the distribution mechanism for functionality, the cookbook  
> > is.
> > 
> > As Dan said though, we probably need to see more code to understand the  
> > full issue
> > 
> > On Wed, May 29, 2013 at 10:07 AM, Ranjib Dey [dey.ranjib@gmail.com](mailto:dey.ranjib@gmail.com)wrote:
> > 
> > i think its fine to include recipes via provider (or rather execute a  
> > whole recipe)
> > 
> > create a subcontext , and a mini chef run inside it, and converge the  
> > node. this is how we used to reuse existing chef resource inside an lwrp  
> > earlier..  
> > yfeldblum had a gist on it..
> > 
> > [http://realityforge.org/code/2012/07/17/lwrp-notify-on-changed-resources.html](http://realityforge.org/code/2012/07/17/lwrp-notify-on-changed-resources.html)
> > 
> > On Wed, May 29, 2013 at 9:46 AM, Dorian Jaminais \<  
> > [dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com)\> wrote:
> > 
> > Yes this can be a workaround, still I don't think the behavior I am  
> > getting is normal (and don't understand why) and I'd prefer to find a  
> > cleaner way than having to add a recipe just to include other recipes  
> > whereas it should be the task of my LWRP.
> > 
> > 2013/5/29 John E. Vincent (lusis) [lusis.org+chef-list@gmail.com](mailto:lusis.org+chef-list@gmail.com)
> > 
> > Is there a reason you wouldn't, however, just add the "include\_recipe"  
> > statements to the default recipe for the LWRP cookbook then? It's not  
> > uncommon to do that even for library cookbooks iirc and it gets around (I  
> > think) the issue you're describing.
> > 
> > On Wed, May 29, 2013 at 12:39 PM, Dorian Jaminais \<  
> > [dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com)\> wrote:
> > 
> > Okay
> > 
> > I am using a LWRP instead of a recipe because I want to deploy about 15  
> > applications that are very similar.  
> > All those applications have a dedicated cookbook but as the installation  
> > process is always the same work flow, I have factorized it into a LWRP.
> > 
> > The work flow is pretty simple : assert that installation dependencies  
> > are met, clone the repo, bundle install the needed gems.
> > 
> > I have attached my provider to this mail (which by the way is included in  
> > a cookbook named gios).
> > 
> > In each application's cookbook I use :  
> > gios\_installer NAME do  
> > name NAME  
> > repository GIT\_URI  
> > command "./bin/truc"  
> > version "master"  
> > action :install  
> > end
> > 
> > As stated in my previous emails, using the LWRP that way will include the  
> > recipes ruby, git, base::certificate, pm-openssh::rsa and  
> > pm-openssh::known\_hosts only if the LWRP is called exactly once in the  
> > run\_list.
> > 
> > Thanks for your help
> > 
> > 2013/5/29 Daniel DeLeo [dan@kallistec.com](mailto:dan@kallistec.com)
> > 
> > On Wednesday, May 29, 2013 at 9:06 AM, Dorian Jaminais wrote:
> > 
> > I am still tracking down my problem and I have some news.  
> > It appears that he problem is not specific to the git cookbook.  
> > Indeed it appears that all recipes included in a LWRP  
> > 'run\_context.include\_recipe' is only really added to the run\_list if the  
> > LWRP is called once during the run\_list.
> > 
> > If the LWRP is called more than once, it tells me that the resource has  
> > already been added to the run\_list even if it has not.
> > 
> > Is this a known bug ? I am doing something wrong ?  
> > I am failing to find any clues using my google-fu so I am turning to your  
> > expertise.
> > 
> > 2013/5/29 Dorian Jaminais [dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com)
> > 
> > Hi everyone
> > 
> > I am having trouble with LWRP, include\_recipe and roles.
> > 
> > I have a LWRP that includes some cookbooks :  
> > run\_context.include\_recipe "git"  
> > run\_context.include\_recipe "internal-cookbook"  
> > run\_context.include\_recipe "build-essential"
> > 
> > This is a bit odd. Why does the LWRP do this instead of a recipe? Showing  
> > more code, log output, and explaining why you're doing things this way  
> > would help others to understand your issue better.
> > 
> > --  
> > Daniel DeLeo
> > 
> > --  
> > Dorian JAMINAIS  
> > _System Administrator_  
> > +33 6 95 10 95 37  
> > [http://perfect-memory.com](http://perfect-memory.com)
> > 
> > [https://twitter.com/semanticbus](https://twitter.com/semanticbus)[http://www.facebook.com/pages/Perfect-Memory/155555567821817](http://www.facebook.com/pages/Perfect-Memory/155555567821817)
> > 
> > --  
> > Dorian JAMINAIS  
> > _System Administrator_  
> > +33 6 95 10 95 37  
> > [http://perfect-memory.com](http://perfect-memory.com)
> > 
> > [https://twitter.com/semanticbus](https://twitter.com/semanticbus)[http://www.facebook.com/pages/Perfect-Memory/155555567821817](http://www.facebook.com/pages/Perfect-Memory/155555567821817)

---

<div class="post-metadata">

**Author:** ![kallistec](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/kallistec/32/23_2.png) [@kallistec](https://discourse.chef.io/u/kallistec)\
**Post date:** [May 29, 2013, 10:43pm UTC](https://discourse.chef.io/t/run-context-include-recipe-in-a-recipe-within-a-role/4032/16 "2013-05-29T22:43:07Z")

</div>

On Wednesday, May 29, 2013 at 12:07 PM, John E. Vincent (lusis) wrote:

> I'm still confused by this. The windows and runit resources, as an example, are not available to a recipe unless include\_recipe is used at the top. They've always failed for me otherwise (regardless of including the dependency in metadata.rb). I never bothered to revisit if this was a bug and I've always done include\_recipe "runit" (or any recipe for that matter) where I needed the resources from that LWRP in the recipe itself.
> 
> I'm totally willing to admit I've been wrong all this time but there was a reason I did it at one point and it fixed the problem at the time. I just never went back and challenged that assumption.  
> LWRPs, resource definitions, etc. are loaded from all available cookbooks (modulo a caveat that chef-solo now requires metadata deps to consider a cookbook "available"). Relevant Chef 11 code: [chef/lib/chef/run\_context/cookbook\_compiler.rb at main · chef/chef · GitHub](https://github.com/opscode/chef/blob/master/lib/chef/run_context/cookbook_compiler.rb#L57-75)

If you're talking about a LWRP or resource definition actually being able to succeed, then you will definitely need whatever system state it depends on to be available. Using runit as an example, you could probably write a "install-runit-my-own-way" cookbook to get runit on the system and then use the runit resource (resource definition until recently) without issue, but it definitely won't work if you haven't installed runit.

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?

--  
Daniel DeLeo

---

<div class="post-metadata">

**Author:** ![Jesse\_Nelson](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/jesse_nelson/32/262_2.png) [@Jesse\_Nelson](https://discourse.chef.io/u/Jesse_Nelson)\
**Post date:** [May 30, 2013, 1:29am UTC](https://discourse.chef.io/t/run-context-include-recipe-in-a-recipe-within-a-role/4032/17 "2013-05-30T01:29:08Z")

</div>

What about the case where you include\_recipe from your provider in a rescue gem require. so get the gem installed and continue on.

I think this case is ok. If the wrapper wants to change the behavior they can, and as an author I can set an attribute to disable the include or return from the included recipe. Possibly Install some other gem that satisfies the dep.

The reason for wanting to do this is hide the implementation.

LWRPs should just work for the common case IMO.

An alternative that i have used is an explicit cookbook::library recipe that handles the setup for just the lib/LWRP. Usage. I like this as an operator because I can see this on the run\_list and know the intent.

On May 29, 2013, at 3:43 PM, Daniel DeLeo [dan@kallistec.com](mailto:dan@kallistec.com) wrote:

> On Wednesday, May 29, 2013 at 12:07 PM, John E. Vincent (lusis) wrote:
> 
> > I'm still confused by this. The windows and runit resources, as an example, are not available to a recipe unless include\_recipe is used at the top. They've always failed for me otherwise (regardless of including the dependency in metadata.rb). I never bothered to revisit if this was a bug and I've always done include\_recipe "runit" (or any recipe for that matter) where I needed the resources from that LWRP in the recipe itself.
> > 
> > I'm totally willing to admit I've been wrong all this time but there was a reason I did it at one point and it fixed the problem at the time. I just never went back and challenged that assumption.  
> > LWRPs, resource definitions, etc. are loaded from all available cookbooks (modulo a caveat that chef-solo now requires metadata deps to consider a cookbook "available"). Relevant Chef 11 code: [chef/lib/chef/run\_context/cookbook\_compiler.rb at main · chef/chef · GitHub](https://github.com/opscode/chef/blob/master/lib/chef/run_context/cookbook_compiler.rb#L57-75)
> 
> If you're talking about a LWRP or resource definition actually being able to succeed, then you will definitely need whatever system state it depends on to be available. Using runit as an example, you could probably write a "install-runit-my-own-way" cookbook to get runit on the system and then use the runit resource (resource definition until recently) without issue, but it definitely won't work if you haven't installed runit.
> 
> 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?
> 
> --  
> Daniel DeLeo

---

<div class="post-metadata">

**Author:** ![Joseph\_Holsten](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/joseph_holsten/32/69_2.png) [@Joseph\_Holsten](https://discourse.chef.io/u/Joseph_Holsten)\
**Post date:** [May 30, 2013, 8:44am UTC](https://discourse.chef.io/t/run-context-include-recipe-in-a-recipe-within-a-role/4032/18 "2013-05-30T08:44:40Z")

</div>

lusis: I think `include_recipe` is no longer required to access libraries in chef 11, but I vaguely rembemer this being an issue in chef \<= 10. I'm pretty sure that's why many library cookbooks have nop recipes/default.rb files.

Also, `include_recipe` used to be unavailable in the lwrp dsl, which was one of the many reasons I just used heavyweight RPs for a long time. I'm pretty sure this is also no longer true.

## And now I want to grumble like an old man. Stupid newfangled DSLs fixing all the things that confused me when I started...

~j

On 2013-05-29, at 12:07, John E. Vincent (lusis) [lusis.org+chef-list@gmail.com](mailto:lusis.org+chef-list@gmail.com) wrote:

> I'm still confused by this. The windows and runit resources, as an example, are not available to a recipe unless include\_recipe is used at the top. They've always failed for me otherwise (regardless of including the dependency in metadata.rb). I never bothered to revisit if this was a bug and I've always done include\_recipe "runit" (or any recipe for that matter) where I needed the resources from that LWRP in the recipe itself.
> 
> I'm totally willing to admit I've been wrong all this time but there was a reason I did it at one point and it fixed the problem at the time. I just never went back and challenged that assumption.
> 
> On Wed, May 29, 2013 at 2:58 PM, Ranjib Dey [dey.ranjib@gmail.com](mailto:dey.ranjib@gmail.com) wrote:  
> no.. you dont have to.. the libraries and lwrps are available just by declaring the dependency, u dont have to include the parent cookbook's default or any other recipe.
> 
> On Wed, May 29, 2013 at 11:00 AM, Cassiano Leal [cassianoleal@gmail.com](mailto:cassianoleal@gmail.com) wrote:  
> Just to understand better, do I actually need to include a library cookbook's recipe in the run\_list of a node in order to use its LWRPs?
> 
> I remember a thread not long ago in this mailing list about "how to test library cookbooks without recipes" or something like that, and someone specifically mentioned that requiring the lib cookbook in the metadata file would be enough.
> 
> Just checking. 🙂
> 
> - cassiano
> 
> On Wednesday, May 29, 2013 at 14:45, Ranjib Dey wrote:
> 
> > i think both are fine, the non lwrp way. u'll be introducing the conditionals inside the recipe.. which will
> > 
> > 1. reduce the declarativeness of the recipe
> > 2. u'll be limited by the compile time info , in certain cases
> > 3. testing will be harder
> > 
> > the lwrp opens up a much cleaner way to reuse this, brings the conditionals inside an abstraction, and also allows you to set your resource's update status depending upon the entire dependency (i.e. now you can say i was updated if any of the dependant resource were update), which you might exploit using notification mechanism is anywhere else... u'll lose most of this if you push these logic in the recipe...  
> > no?
> > 
> > On Wed, May 29, 2013 at 10:38 AM, Sean Escriva [sean.escriva@gmail.com](mailto:sean.escriva@gmail.com) wrote:
> > 
> > > very neat.
> > > 
> > > Notifications from the lwrp are one thing, but IMO include\_recipe shouldn't need to be in the lwrp because as John mentioned the cookbook that provides the lwrp still needs to be included to make use of the specific lwrp and as such will run the default recipe. It should also result in a simpler lwrp. This seems easier to reason about as well since the lwrp is not the distribution mechanism for functionality, the cookbook is.
> > > 
> > > As Dan said though, we probably need to see more code to understand the full issue
> > > 
> > > On Wed, May 29, 2013 at 10:07 AM, Ranjib Dey [dey.ranjib@gmail.com](mailto:dey.ranjib@gmail.com) wrote:
> > > 
> > > > i think its fine to include recipes via provider (or rather execute a whole recipe)
> > > > 
> > > > create a subcontext , and a mini chef run inside it, and converge the node. this is how we used to reuse existing chef resource inside an lwrp earlier..  
> > > > yfeldblum had a gist on it..
> > > > 
> > > > [LWRP notifying on changed resources](http://realityforge.org/code/2012/07/17/lwrp-notify-on-changed-resources.html)
> > > > 
> > > > On Wed, May 29, 2013 at 9:46 AM, Dorian Jaminais [dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com) wrote:
> > > > 
> > > > > Yes this can be a workaround, still I don't think the behavior I am getting is normal (and don't understand why) and I'd prefer to find a cleaner way than having to add a recipe just to include other recipes whereas it should be the task of my LWRP.
> > > > > 
> > > > > 2013/5/29 John E. Vincent (lusis) [lusis.org+chef-list@gmail.com](mailto:lusis.org+chef-list@gmail.com)
> > > > > 
> > > > > > Is there a reason you wouldn't, however, just add the "include\_recipe" statements to the default recipe for the LWRP cookbook then? It's not uncommon to do that even for library cookbooks iirc and it gets around (I think) the issue you're describing.
> > > > > > 
> > > > > > On Wed, May 29, 2013 at 12:39 PM, Dorian Jaminais [dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com) wrote:
> > > > > > 
> > > > > > > Okay
> > > > > > > 
> > > > > > > I am using a LWRP instead of a recipe because I want to deploy about 15 applications that are very similar.  
> > > > > > > All those applications have a dedicated cookbook but as the installation process is always the same work flow, I have factorized it into a LWRP.
> > > > > > > 
> > > > > > > The work flow is pretty simple : assert that installation dependencies are met, clone the repo, bundle install the needed gems.
> > > > > > > 
> > > > > > > I have attached my provider to this mail (which by the way is included in a cookbook named gios).
> > > > > > > 
> > > > > > > In each application's cookbook I use :  
> > > > > > > gios\_installer NAME do  
> > > > > > > name NAME  
> > > > > > > repository GIT\_URI  
> > > > > > > command "./bin/truc"  
> > > > > > > version "master"  
> > > > > > > action :install  
> > > > > > > end
> > > > > > > 
> > > > > > > As stated in my previous emails, using the LWRP that way will include the recipes ruby, git, base::certificate, pm-openssh::rsa and pm-openssh::known\_hosts only if the LWRP is called exactly once in the run\_list.
> > > > > > > 
> > > > > > > Thanks for your help
> > > > > > > 
> > > > > > > 2013/5/29 Daniel DeLeo [dan@kallistec.com](mailto:dan@kallistec.com)
> > > > > > > 
> > > > > > > > On Wednesday, May 29, 2013 at 9:06 AM, Dorian Jaminais wrote:
> > > > > > > > 
> > > > > > > > > I am still tracking down my problem and I have some news.  
> > > > > > > > > It appears that he problem is not specific to the git cookbook.  
> > > > > > > > > Indeed it appears that all recipes included in a LWRP 'run\_context.include\_recipe' is only really added to the run\_list if the LWRP is called once during the run\_list.
> > > > > > > > > 
> > > > > > > > > If the LWRP is called more than once, it tells me that the resource has already been added to the run\_list even if it has not.
> > > > > > > > > 
> > > > > > > > > Is this a known bug ? I am doing something wrong ?  
> > > > > > > > > I am failing to find any clues using my google-fu so I am turning to your expertise.
> > > > > > > > > 
> > > > > > > > > 2013/5/29 Dorian Jaminais [dorian.jaminais@perfect-memory.com](mailto:dorian.jaminais@perfect-memory.com)
> > > > > > > > > 
> > > > > > > > > > Hi everyone
> > > > > > > > > > 
> > > > > > > > > > I am having trouble with LWRP, include\_recipe and roles.
> > > > > > > > > > 
> > > > > > > > > > I have a LWRP that includes some cookbooks :  
> > > > > > > > > > run\_context.include\_recipe "git"  
> > > > > > > > > > run\_context.include\_recipe "internal-cookbook"  
> > > > > > > > > > run\_context.include\_recipe "build-essential"
> > > > > > > > 
> > > > > > > > This is a bit odd. Why does the LWRP do this instead of a recipe? Showing more code, log output, and explaining why you're doing things this way would help others to understand your issue better.
> > > > > > > > 
> > > > > > > > --  
> > > > > > > > Daniel DeLeo
> > > > > > > 
> > > > > > > --  
> > > > > > > Dorian JAMINAIS  
> > > > > > > System Administrator  
> > > > > > > +33 6 95 10 95 37
> > > > > 
> > > > > --  
> > > > > Dorian JAMINAIS  
> > > > > System Administrator  
> > > > > +33 6 95 10 95 37

---

<div class="post-metadata">

**Author:** ![realityforge](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/realityforge/32/395_2.png) [@realityforge](https://discourse.chef.io/u/realityforge)\
**Post date:** [May 30, 2013, 10:54am UTC](https://discourse.chef.io/t/run-context-include-recipe-in-a-recipe-within-a-role/4032/19 "2013-05-30T10:54:40Z")

</div>

Hi,

On Thu, May 30, 2013 at 8:43 AM, Daniel DeLeo [dan@kallistec.com](mailto: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

---

<div class="post-metadata">

**Author:** ![Dorian\_Jaminais](https://avatars.discourse-cdn.com/v4/letter/d/ce7236/32.png) [@Dorian\_Jaminais](https://discourse.chef.io/u/Dorian_Jaminais)\
**Post date:** [May 30, 2013, 12:22pm UTC](https://discourse.chef.io/t/run-context-include-recipe-in-a-recipe-within-a-role/4032/20 "2013-05-30T12:22:12Z")

</div>

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](mailto:peter@realityforge.org)

> Hi,
> 
> On Thu, May 30, 2013 at 8:43 AM, Daniel DeLeo [dan@kallistec.com](mailto: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](http://perfect-memory.com)

[https://twitter.com/semanticbus](https://twitter.com/semanticbus)[http://www.facebook.com/pages/Perfect-Memory/155555567821817](http://www.facebook.com/pages/Perfect-Memory/155555567821817)

[Next page](https://discourse.chef.io/t/run-context-include-recipe-in-a-recipe-within-a-role/4032.md?page=2)
