Monkey patch a puppet provider
I just wanted to monkey patch the puppet package provider for gentoo portage.
But why?
# puppet resource package
Only shows packages installed by puppet, but not packages installed by hand. The apt/dpkg- and yum/rpm-provider list all packages.
It was not enough to place a lib/puppet/provider/package/portage.rb. In all my tests, the original behavior was kept. I only want to replace one function.
But how?
When registering new type or providers, etc, puppet is doing a bunch of magick in the background. So first, I have to figure out the name of the automagically created class.
https://github.com/puppetlabs/puppet/blob/master/lib/puppet/provider/package/portage.rb#L4
Puppet::Type.type(:package).provide :portage, :parent=> Puppet::Provider::Packagedo
...
end
Trying this in irb
irb(main):001:0> require 'puppet'
irb(main):002:0> Puppet::Type.type(:package).provide :SOMETEST
=> Puppet::Type::Package::ProviderSometest
Hmm. Is it that simple? In one of our modules, I generated a file lib/puppet/provider/package/portage_zz.rb
require 'puppet'
class Puppet::Type::Package::ProviderPortage
   private
   def self.eix_search_format
     "'<category> <name> [<installedversions:LASTVERSION>] [<bestversion:LASTVERSION>] <homepage> <description>\n'"
   end
end
I called it portage_zz.rb, to be sure it will be loaded after the regular portage.rb.
However, the puppet run with pluginsync shipped this file. And... puppet resource package list all packages :)