- From: Simon Detheridge <
>
- To:
- Subject: [chef] Re: Re: Programmatic creation/deletion of resources
- Date: Thu, 7 May 2015 16:58:09 +0100 (BST)
----- On 7 May, 2015, at 16:23, Daniel DeLeo
wrote:
>
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
Thanks, that is very much what I'm looking for.
Follow-up: My resource has a fairly large number of potential attributes. Is
there a way I can set them in a less DSL-like way? For example:
nxlog_source "name" do
{"hash": "with", "a": "bunch", "of": "pairs"}.each_pair do |k,v|
set_attribute k, v
end
end
as opposed to
resource_attr1 node_attrs["resource_attr1"]
...
resource_attr50 node_attrs["resource_attr50"]
This way I can not repeat myself and avoid having to maintain a file with
another list of my resource attributes...
>
> - 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.
Yeah, it's files in a conf.d. I think the issue that I'm grappling with is
that let's say someone has used node attributes to create a source, but
elsewhere someone has used a lwrp to create a different source in another
recipe... How can I ensure I don't clean up the source that's been defined
via the lwrp instead of the node attributes?
Thanks,
--
Simon Detheridge - CTO, Widgit Software
26 Queen Street, Cubbington, CV32 7NA - Tel: +44 (0)1926 333680
Archive powered by MHonArc 2.6.16.