On 28/04/14 16:45, R. Tyler Croy wrote:
> In my previous thread "Can I make my entire module "depend" on
> rubygems being installed?" I think I mischaracterized the problem.
> 
> 
> Basically, I would like to use a Ruby gem inside of a Puppet module
> which contains a custom provider. There's an inherent problem in
> this appraoch, for example:
> 
> class { 'jenkins' : require => Package[mygem]; }
> 
> This iwll require *two* Puppet runs to operate correctly, one to
> install the gem properly, and the second to load the gem properly
> into the Puppet runtime environment.

This is possible using "features" (that is, system features, not
provider features).  You first write a feature definition that says
you expect library X to become available.  You then confine your
provider to depend that feature being available, the Puppet will delay
evaluation of those resources until the feature becomes available in
the same way it does with commands.  This has been available since
2.7.20 (ticket #14822).

Here's an example of a feature:
https://github.com/theforeman/puppet-foreman/blob/master/lib/puppet/feature/foreman_api.rb.
 The "libs" argument has to be the name of the library passed to require.

The confine looks like this:
https://github.com/theforeman/puppet-foreman/blob/master/lib/puppet/provider/foreman_smartproxy/rest.rb#L3

However there's a gotcha if you're requiring gems, as we have to flush
the load paths or they get cached with the currently loaded set of
gems.  This has only just been fixed for Puppet 3.6.0:
https://tickets.puppetlabs.com/browse/PUP-1879

I can't really think of a workaround for this issue either, unless you
can figure out how to run some arbitrary code after each resource is
evaluated to clear cached paths.

-- 
Dominic Cleal
Red Hat Engineering

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-dev/535E7B1B.4030808%40redhat.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to