Ask Your Question
1

Extending a module to add custom functionality

asked 2015-07-08 11:46:38 -0500

udaysagar gravatar image

Hello,

I am working on modifying the puppet-module-collectd from github so that I can install the collectd package from a PPA for debian systems instead of using the apt provider (as given in the module). I also need to customize the plugins.

So, I have created a different module (say my-collectd) that adds the extra functionality. My class inherits the base class of puppet-module-collectd and overrides the existing package resource by appending one more attribute.

class my_collectd::custom_install (
        $purge        = true,
        $recurse      = true,
        $purge_config = true,
) inherits collectd {
    # case statement to identify debian
    Package['collectd'] {
        require +> # some exec commands that will add the ppa to the sources.list
    }
}

The problem is, the base class - collectd is a parameterized class. And I have to supply some parameters(as given in the official github documentation) to customize the plugins.

class { '::collectd':
  purge        => true,
  recurse      => true,
  purge_config => true,
}

I figured out from various sources that I cannot set the parameters of base class from inherited class. Is there any other way to achieve the desired target - set parameters to override functionality AND override package resource attributes

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-07-10 11:51:40 -0500

ramindk gravatar image

Simpler to wrap it in a profile class. Also fits in nice with Role/Profile which is a common organizational pattern in Puppet code.

class profile::collectd {

  # I'd skip this entirely and just use the apt module or write my own apt module
  exec { 'add collectd ppa': }

  class { '::collectd':
    purge        => true,
    recurse      => true,
    purge_config => true,
    require => Exec['add collectd ppa'],
  }
}
edit flag offensive delete link more

Comments

Thanks ramindk. Can you tell me how to declare the original collectd module as a dependency to my module and install it before mine.

udaysagar gravatar imageudaysagar ( 2015-07-27 13:52:11 -0500 )edit

Not really sure what you mean. The collectd module is being declared in the wrapper class.

ramindk gravatar imageramindk ( 2015-07-28 13:31:12 -0500 )edit

I meant how to tell puppet to install collectd module before installing my module so that there will no errors when I try to use collectd inside my wrapper class. I found the answer: I have to list collectd as a dependency in my metadata.json

udaysagar gravatar imageudaysagar ( 2015-11-13 13:45:45 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-07-08 11:46:38 -0500

Seen: 600 times

Last updated: Jul 10 '15