- From: Peter Donald <
>
- To: Chef Mailing List <
>
- Subject: [chef] Re: Best pattern for automatically creating/deleting resources based on what has changed?
- Date: Sun, 13 Oct 2013 15:01:54 +1100
We do this pretty extensively in a lot of our cookbooks. The way we
have found that works best for us is to collect the complete set of
data for that widget system using arbitrary mechanism X (i.e. load it
out of data bags, search other nodes, load from ldap etc).
Then we record the complete state of the widget system as attributes
on the node. Then we call a recipe named something like
'widget::attribute_driven'. This recipe is responsible for
"interpreting" the attribute data and calling out to other resources
to do the work. At the end it will inspect the widget system and find
any widgets that are configured and not present in the attribute data.
It will then perform the appropriate 'remove'.
Examples of this can be seen at [1] where we configure the glassfish
application server using this technique and [2] where we configure sql
server using this technique.
[1]
https://github.com/realityforge/chef-glassfish/blob/master/recipes/attribute_driven_domain.rb
[2]
https://github.com/realityforge/chef-sqlshell/blob/master/recipes/ms_attribute_driven.rb
HTH
On Thu, Oct 10, 2013 at 5:32 PM, Christopher Armstrong
<
>
wrote:
>
Say I have a directory that Chef maintains which is full of JSON files. I
>
have an LWRP which writes these JSON files to the directory. For example's
>
sake, let's say the resource is widget:
>
>
widget "widget1" do
>
created_by "chris"
>
owned_by "john"
>
end
>
>
widget "widget2" do
>
created_by "john"
>
owned_by "chris"
>
end
>
>
etc...
>
>
Great. Chef runs, and it ensures that I have these JSON files and that the
>
content is what I expect. Now, if I want to remove a widget, I have to
>
update my cookbook and run Chef:
>
>
widget "widget2" do
>
action :delete
>
end
>
>
Obviously, this is clunky. I'd like to rewrite my LWRP so that it reads the
>
files in the directory, "plays" my changes on top of them, and then cleans
>
up what I don't want. So, if I start with two files in that directory but my
>
Chef recipe only creates one widget, the other will automatically be
>
deleted. In my Chef output, I should see that one was deleted. Is the way to
>
approach this to create resources from each of the existing files, and then
>
run :delete on the difference?
>
>
Is there an existing pattern for this, or an example cookbook which already
>
does this that I can use as an example?
>
>
Any help is appreciated!
>
>
Thanks,
>
Chris
--
Cheers,
Peter Donald
Archive powered by MHonArc 2.6.16.