- From: Peter Donald <
>
- To:
- Subject: [chef] Re: Re: Re: Re: updated_by_last action from a resource inside a LWP
- Date: Tue, 17 Jul 2012 11:47:40 +1000
Hi,
On Tue, Jul 17, 2012 at 1:30 AM,
<
>
wrote:
>
yfeldblum pointed me to a great pattern for dealing with this. Here is the
>
gist
>
>
https://gist.github.com/d85be145f3ff824ccc07/0e97d44f20ec65411b141cb46cbeb19bb34b44ad
>
>
The general idea is you cache your current run_context, create a new one,
>
blank
>
out the resource collection, perform all your resource actions. Then you
>
restore the run_context back to the original and converge on the new run
>
context you created. This sub run context contains the subset of resources
>
acted upon in your provider. Then you call converge on the sub run context
>
and
>
check each of its resources to see if they were updated. If any did get
>
updated you pass that along to your new_resource.
>
>
Awesome and nifty. I implemented in my redisio cookbook in the install
>
provider and it seems to work great.
Awesome indeed. I have tested it out and it works fine and dandy for
me. Except we have lots of LWRPs so doing this everytime would be
tiresome. I abstracted the essential goodness into a method
notifying_action and now most of my providers look something like
notifying_action :run do
file "/tmp/something" do
owner "root"
group "root"
mode "0755"
action :create
end
end
Much nicer!
Anyhoo I documented for posterity at
http://realityforge.org/code/2012/07/17/lwrp-notify-on-changed-resources.html
--
Cheers,
Peter Donald
Archive powered by MHonArc 2.6.16.