[chef] Best pattern for automatically creating/deleting resources based on what has changed?


Chronological Thread 
  • From: Christopher Armstrong < >
  • To:
  • Subject: [chef] Best pattern for automatically creating/deleting resources based on what has changed?
  • Date: Wed, 9 Oct 2013 23:32:23 -0700

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



Archive powered by MHonArc 2.6.16.

§