I came across a similar chicken/egg scenario when I was writing a
custom package provider which needed to leverage a gem that I knew did
not exist on the system. Here's how I solved it in my provider:

  def gem_dependency(name, package =
nil)
    raise Puppet::Error, "Required 'name' argument must be a string."
unless name.is_a?
String
    package = name if
package.nil?
 
begin
      require
"#{name}"
    rescue
LoadError
 
begin
        puppet_package_provider(package,
"gem")
      rescue
Exception
        puppet_package_provider(package, "gem", "http://
gems.rubyforge.org")
 
end
 
Gem.clear_paths
 
retry
 
end
  end

  # Installs a package with
Puppet
  # source should not be required so the provider can use its
configured
default(s)
  def puppet_package_provider(package, provider, source =
nil)

    if
source.nil?
      ppp = Puppet::Type.type(:package).new(:name =>
"#{package}", :provider =>
provider).provider
 
else
      ppp = Puppet::Type.type(:package).new(:name =>
"#{package}", :provider => provider, :source =>
source).provider
 
end

    ppp.install if ppp.properties[:ensure]
== :absent
  end

Then in my install method...

def install

  gem_dependency('sys/filesystem', 'sys-filesystem')

end

The magic happens with the call to Gem.clear_paths

Best,
Adam

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to