- From: Daniel DeLeo <
>
- To:
- Subject: [chef] Re: Programmatic creation/deletion of resources
- Date: Thu, 7 May 2015 08:23:12 -0700
On Thursday, May 7, 2015 at 6:17 AM, Simon Detheridge wrote:
>
Hello,
>
>
I'm putting together a cookbook to manage nxlog
>
(https://git.widgit.com/widgit-cookbooks/nxlog) which manages routing log
>
data from one place to another. I've created some LWRPs for log sources and
>
destinations. (nxlog_source, nxlog_destination)
>
>
I'd like to add a mechanism to automatically create log sources and
>
destinations from node attributes. For example:
>
node['nxlog']['sources'] = [ { some_data }, { different_data } ]
>
>
I figured this could be easier in some cases than modifying existing
>
recipes or creating new ones.
>
>
I'm not sure about the best way to go about this... The things I'm
>
currently stuck on are:
>
>
- How do I programatically create a new resource? i.e.
>
>
node['nxlog']['sources'].each { |source| create_source(source) }
>
-- I'm not sure how I would implement `create_source`
What do you imagine create_source does? Creates a resource with the resource
attributes filled out from the node attributes? That can be accomplished by
writing a ruby module with a method, like
https://gist.github.com/danielsdeleo/d4511904a41a9a682c04
>
>
- How do I enumerate currently-extant resources so that I can delete ones
>
that have been removed? (or... is this even possible?)
>
>
for example: If I've removed an element from the 'sources' array how can I
>
ensure that the resource's config file is cleaned up on the node?
What thing on the system represents the stuff that exists? Are these
individual files (sounds like yes)? As long as there aren’t unmanaged files
in that particular directory, you can use Ruby’s Dir.glob to enumerate the
existing files and compare to the list of things you want, and remove the
extra elements.
>
>
Hope this makes sense... Thanks,
>
Simon
>
>
--
>
Simon Detheridge - CTO, Widgit Software
>
26 Queen Street, Cubbington, CV32 7NA - Tel: +44 (0)1926 333680
HTH,
--
Daniel DeLeo
Archive powered by MHonArc 2.6.16.