Monkey patch puppet type

86 views
Skip to first unread message

Mickaël Canévet

unread,
Aug 24, 2014, 2:04:07 AM8/24/14
to puppet...@googlegroups.com
Hello,

I'd like to know if there is a way to monkey patch a puppet type for example to add an auto requirement:


Thanks,
Mickaël

Felix Frank

unread,
Aug 25, 2014, 5:14:11 PM8/25/14
to puppet...@googlegroups.com
Well, you can always maintain your personal fork of the firewall module,
and include that patch.

For core types, you will have to build your own packages (if that's how
you install your agents).

Is that what you're asking?

Best,
Felix

Mickaël Canévet

unread,
Aug 26, 2014, 2:38:30 AM8/26/14
to puppet...@googlegroups.com
Well, actually no. I'd really like to be able to provide a monkey patch that will apply on top of puppetlabs's module so that I don't have to maintain a fork (which is what I do right now) while my patch is not accepted upstream.
As declaring a parent for a puppet type is obsolete, I can't use inheritance to do that, that's why I was wondering if monkey patching could do the trick.

Thanks,
Mickaël

Felix Frank

unread,
Aug 26, 2014, 9:48:04 AM8/26/14
to puppet...@googlegroups.com
On 08/26/2014 08:38 AM, Mickaël Canévet wrote:
>
> Well, actually no. I'd really like to be able to provide a monkey patch
> that will apply on top of puppetlabs's module so that I don't have to
> maintain a fork (which is what I do right now) while my patch is not
> accepted upstream.
> As declaring a parent for a puppet type is obsolete, I can't use
> inheritance to do that, that's why I was wondering if monkey patching
> could do the trick.

Yes, that patch looks a mite problematic ;-)

Apparently you can indeed monkeypatch stuff.

irb(main):001:0> require 'puppet'
irb(main):012:0> class Puppet::Type::File
irb(main):013:1> autorequire :package do |res|
irb(main):014:2* 'coreutils'
irb(main):015:2> end
irb(main):016:1> end
=> #<Proc:0x000000037af7d0@(irb):13>

It might be tricky to get Ruby to load your code at an appropriate time,
but It Should Work.

Quick reminder that I grant no warranty for the well-being of your
firewalls ;-)

Cheers,
Felix

Mickaël Canévet

unread,
Aug 26, 2014, 10:22:07 AM8/26/14
to puppet...@googlegroups.com
Thanks for your help.
We put the code in lib/puppet/provider to ensure that it is loaded after the type.

Cheers,
Mickaël 
Reply all
Reply to author
Forward
0 new messages