Interacting with RAL from a types generate method.

18 views
Skip to first unread message

Craig Dunn

unread,
Aug 23, 2016, 4:00:06 PM8/23/16
to puppe...@googlegroups.com

Hi all

I'm after a bit of advice on talking to some Puppet internals... background;  I have a module called crayfishx/purge which so far has proved pretty stable and useful.  It works on the same principle as the resources resource in Puppet, in so far that it spits out resources from the generate method of its type (it also has some way cooler features than resources).  Here's how we currently do it...


That works, but I'm working on a bit of a refactor, the main issue I'm trying to overcome is https://github.com/crayfishx/puppet-purge/issues/5


I'm not too worried about the first example, but the second one is proving tricky to solve in a nice way.  The problem here is that any resources spat out from the generate are floating outside of the dependency graph therefore there is no way to pin dependencies on them.  In that example I want the exec to trigger once all the resources have actually been purged.

So, following that train of thought I'm trying actually yo get the resources in their desired state during the execution of the generate method so, when the purge resource goes into a change state, we can be sure that all the resources have already been purged, and therefore we can notify stuff to do afterwards.

I've played around with some ways today (some of them almost worked, some of them bat shit crazy), but talking directly to the should=, sync and flush methods of types just doesn't seem very generic and i kept hitting problems.

My final stab at getting this to work was just to create a new catalog object and apply it in this method.... here is what I've currently got thats sitting in the master branch....



That code actually works, and from a functional point of view it does what I want, so I guess my main questions are;

* Is this is a _really_ bad idea and if so why?
* Is there a better way?

The main issue here is that rather than throwing things randomly in the catalog to be actioned some time in the future,  I want to be sure that the desired state has been maintained when the purge resource has been evaluated.  That is happening now and I'm getting the desired results.....



.... but I don't want to be this guy.....


Suggestions really welcome,

Thanks
Craig


--
Enviatics     |      Automation and Configuration Management
Puppet Labs Service Delivery Partner & Certified Consultant

Craig Dunn

unread,
Aug 24, 2016, 1:18:19 PM8/24/16
to puppe...@googlegroups.com

To anyone following this, I recently stumbled across this https://tickets.puppetlabs.com/browse/PUP-1963 ... Have you ever tried searching for anything to do with the "resources resource"?  It's not very search friendly ;-)

TL;DR, It took a couple of years but this problem was addressed with Puppet 4.3

My original question can be ignored, I've changed the code in master on crayfishx/purge back to something a bit less crazytown as this seems to work as expected with dependencies in 4.3+, we'll just document that relationships aren't supported in Puppet < 4.3, the alternatives are too hacky given the fact there is already a fix in 4.

With that in mind, and as an FYI for any users of the crayfishx/purge module, the latest code (which includes the the ability to define *how* to purge stuff, eg: to unmount mounts rather than delete them), will be tidied up and go out soon as 1.2, not 2.0.

Thanks, from me and Jeff Goldblum.

Craig

Reply all
Reply to author
Forward
0 new messages