# LWRPs as containers

**URL:** <https://discourse.chef.io/t/lwrps-as-containers/1778>\
**Category:** Chef Infra (archive)\
**Created:** [April 19, 2011, 3:13pm UTC](https://discourse.chef.io/t/lwrps-as-containers/1778 "2011-04-19T15:13:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_J\_Reed](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/mark_j_reed/32/776_2.png) [@Mark\_J\_Reed](https://discourse.chef.io/u/Mark_J_Reed)\
**Post date:** [April 19, 2011, 3:13pm UTC](https://discourse.chef.io/t/lwrps-as-containers/1778/1 "2011-04-19T15:13:14Z")

</div>

I have an LWRP that fundamentally just creates a bunch of other  
resources dynamically. I had some issues getting notifies to work, so  
I have some questions.

1. Is an LWRP the best way to create a resource that is really a  
collection of other resources?

2. If not, what is? A define? A straight-up non-lightweight resource  
definition? It’s definitely not a recipe, as I need to be able to  
call/include it multiple times with different parameters.

3. If it’s at least a reasonable way to do it, where in the provider  
does that logic belong? Creating more resources once you’re already  
running the action seems a bit late; I wind up having to call  
run\_action on them as I create them in order to get the behavior I  
want.

4. As far as notifies go, is there a way from the provider to access  
the set of notifications requested?

Any thoughts and recommendations appreciated. Thanks!

–  
Mark J. Reed [markjreed@gmail.com](mailto:markjreed@gmail.com)

---

<div class="post-metadata">

**Author:** ![Adam\_Jacob](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/adam_jacob/32/292_2.png) [@Adam\_Jacob](https://discourse.chef.io/u/Adam_Jacob)\
**Post date:** [April 19, 2011, 5:17pm UTC](https://discourse.chef.io/t/lwrps-as-containers/1778/2 "2011-04-19T17:17:10Z")

</div>

On Tue, Apr 19, 2011 at 8:13 AM, Mark J. Reed [markjreed@gmail.com](mailto:markjreed@gmail.com) wrote:

> I have an LWRP that fundamentally just creates a bunch of other  
> resources dynamically. I had some issues getting notifies to work, so  
> I have some questions.
> 
> 1. Is an LWRP the best way to create a resource that is really a  
> collection of other resources?
> 
> 2. If not, what is? A define? A straight-up non-lightweight resource  
> definition? It's definitely not a recipe, as I need to be able to  
> call/include it multiple times with different parameters.
> 
> 3. If it's at least a reasonable way to do it, where in the provider  
> does that logic belong? Creating more resources once you're already  
> running the action seems a bit late; I wind up having to call  
> run\_action on them as I create them in order to get the behavior I  
> want.
> 
> 4. As far as notifies go, is there a way from the provider to access  
> the set of notifications requested?
> 
> Any thoughts and recommendations appreciated. Thanks!

Can you give us some example code, and tell us what's happening with  
the notifications?

Adam

--  
Opscode, Inc.  
Adam Jacob, Chief Product Officer  
T: (206) 619-7151 E: [adam@opscode.com](mailto:adam@opscode.com)

---

<div class="post-metadata">

**Author:** ![Mark\_J\_Reed](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/mark_j_reed/32/776_2.png) [@Mark\_J\_Reed](https://discourse.chef.io/u/Mark_J_Reed)\
**Post date:** [April 19, 2011, 5:36pm UTC](https://discourse.chef.io/t/lwrps-as-containers/1778/3 "2011-04-19T17:36:16Z")

</div>

Thanks, Adam. I got it working with kallistec's help on IRC. What  
I'm doing now is just duplicating the notifies from the LWRP onto each  
sub resource.

Ex code (abbreviated due to typing on phone):

action :create do  
nr = new\_resource  
@delay = nr.delayed\_notifications  
@imm = nr.immediate\_notifications  
def fw(res)  
if @delay then  
@delay.each do |r|  
res.notifies\_delayed r.action, r.resource  
end  
end  
if @imm then ... #similar  
end  
end

```
 fw( remote_file "foo" do ... end )
 fw( bash "bar" do ... end )
 ...

```

end

Direct setters for the notifications attributes would be helpful here...

On Tuesday, April 19, 2011, Adam Jacob [adam@opscode.com](mailto:adam@opscode.com) wrote:

> On Tue, Apr 19, 2011 at 8:13 AM, Mark J. Reed [markjreed@gmail.com](mailto:markjreed@gmail.com) wrote:
> 
> > I have an LWRP that fundamentally just creates a bunch of other  
> > resources dynamically. I had some issues getting notifies to work, so  
> > I have some questions.
> > 
> > 1. Is an LWRP the best way to create a resource that is really a  
> > collection of other resources?
> > 
> > 2. If not, what is? A define? A straight-up non-lightweight resource  
> > definition? It's definitely not a recipe, as I need to be able to  
> > call/include it multiple times with different parameters.
> > 
> > 3. If it's at least a reasonable way to do it, where in the provider  
> > does that logic belong? Creating more resources once you're already  
> > running the action seems a bit late; I wind up having to call  
> > run\_action on them as I create them in order to get the behavior I  
> > want.
> > 
> > 4. As far as notifies go, is there a way from the provider to access  
> > the set of notifications requested?
> > 
> > Any thoughts and recommendations appreciated. Thanks!
> 
> Can you give us some example code, and tell us what's happening with  
> the notifications?
> 
> Adam
> 
> --  
> Opscode, Inc.  
> Adam Jacob, Chief Product Officer  
> T: (206) 619-7151 E: [adam@opscode.com](mailto:adam@opscode.com)

--  
Mark J. Reed [markjreed@gmail.com](mailto:markjreed@gmail.com)
