Autorequire based on resource property???

36 views
Skip to first unread message

Gavin Williams

unread,
Feb 7, 2014, 6:51:55 AM2/7/14
to puppet...@googlegroups.com
Morning all

I'm trying to work out if it's possible to add auto-require logic to some of my Glassfish module[1] types.

From what I've read about autorequire, the standard usage is to match to a resource title, as used here[2].
However the challenge I'm hitting is that I don't know the title of the resource I need to auto-require in some of my types. However I do know the resource type, and a property of that type.

In other-words, if I want the application resource type to auto-require the appropriate domain resource type, the only information I have to relate is based on the 'portbase' param[3][4].

Is this technically possible? Or am I barking up the wrong tree???

Cheers
Gavin

[1] https://github.com/fatmcgav/puppet-glassfish/
[2] https://github.com/fatmcgav/puppet-glassfish/blob/master/lib/puppet/type/domain.rb#L91-L99
[3] https://github.com/fatmcgav/puppet-glassfish/blob/master/lib/puppet/type/domain.rb#L17-L35
[4] https://github.com/fatmcgav/puppet-glassfish/blob/master/lib/puppet/type/application.rb#L31-L49

Felix Frank

unread,
Feb 7, 2014, 7:50:58 AM2/7/14
to puppet...@googlegroups.com
Hi,

I suppose that should be possible, although the autorequire block will
be a lot more complex than those you're using right now (obviously,
since those are almost trivial - in a good way :-)

You can filter the list of all resources in the catalog for interesting
things to autorequire. This general pattern might get you going
(untested though)

autorequire(...) do
self.catalog.resources.select { |res|
# pseudo-code: resource is of desired type
# and has desired properties/parameters
}.collect { |res|
res[:name]
}
end

Not even sure if :name is the correct key, but I hope this brings the
idea across.

HTH,
Felix

On 02/07/2014 12:51 PM, Gavin Williams wrote:
> In other-words, if I want the /application/ resource type to
> auto-require the appropriate /domain/ resource type, the only
> information I have to relate is based on the '/portbase/' param[3][4].

Gavin Williams

unread,
Feb 7, 2014, 10:39:44 AM2/7/14
to puppet...@googlegroups.com, puppe...@googlegroups.com
Felix

Thanks for the pointers there...

As discussed on #puppet-dev, I've managed to get it working with the following code: https://gist.github.com/fatmcgav/8864343

However it does raise the question of "Is this the most optimal method to handle this scenario?"

As it means iterating the entire catalog for each resource that wants to auto-require another resource. In a practical application, I could see 6+ resources of different types that might want to autorequire the domain resource.
Is there a more efficient method to pull out specific resource types from the catalogue? Or is the overhead from this operation likely to be soo small as not to worry?

Cross posting to Puppet-dev mailing list for comment aswell.

Cheers
Gavin
Reply all
Reply to author
Forward
0 new messages