On Monday, September 22, 2014 2:05:42 PM UTC-5, Vladimir Brik wrote:
> Here's roughly what I am thinking of doing (but I am wondering if there > is a better way). > > site.pp: > # this is in global area of site.pp. so that all nodes, whether > they > # use statlog or not include this code > class { "statlog::autocleanup":} > > node foo { > statlog { "bar":} > } > > statlog module: > class statlog::autocleanup() > { > # real implementation is a bit more complicated to handle > # resource ordering, non-existent services, etc. > if !defined(Service["statlog.baz"]) { > service{ "statlog.baz": > ensure => stopped, > enable => false, > } > } > if !defined(Service["statlog.foo"]) { > ... > } > } > > Is there a better way to do this? > > You have used the defined() function. There is *always* a better way than that. It is unclear to me why, if you want to purge undeclared Statlog resources, what you actually do is manage Service resources. If you want to be able to remove Statlogs, then that type should have an 'ensure' parameter that you can set to 'absent' to cause that resource to be removed. Supposing you have that, a better way to proceed would be more like this: class statlogs::none($all_statlogs) { statlogs::statlog { $all_statlogs: ensure => 'absent' } } node foo { include 'statlogs::none' Statlogs::Statlog <| title == 'bar' |> { ensure => 'present' } } If you wished, it might be a bit nicer to wrap the resource override in its own defined type, maybe something like statlogs::enabled. As I wrote it, class parameter $statlogs::none::all_statlogs is designed to be bound to an Hiera array containing all the possible statlogs. It would be possible to instead populate it with all the statlogs actually present on the target node, as provided by a custom fact. Alternatively, if you wrote the Statlog type as a Ruby plugin type, made it Ensurable, and made it perform prefetching, then you could do the purging part very simply via an instance of the Resources type. Or if you were willing to put all wanted Services under Puppet management, then you could use a Resources to purge unmanaged Service resources, which would be along the lines of what you were thinking of doing. John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/99d46bac-47d2-45d9-a954-bad6f0ec81b4%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.