Ask Your Question

parameterized classes as inheritable base classes

asked 2013-10-25 18:50:41 -0600

timelord gravatar image

Puppet Labs Documentation says:

Puppet 3 does not support using parameterized classes for inheritable base classes. The base class must have no parameters.

but then another PuppetLabs document - Beginner's Guide to Modules - says:

The main class of a module is its interface point and ought to be the only parameterized class if possible. Limiting the parameterized classes to just the main class allows you to control usage of the entire module with the inclusion of a single class.

which is clear and easy to understand ... but then in the example on the same page there's a class ntp ... (more)

edit retag flag offensive close merge delete


Hmm.. Let's think... 1. parameterized base classes do their job well. 2. NTP puppet module is the widely known as an example of best practice in puppet module writing ...(more)

Aleksey Timohin gravatar imageAleksey Timohin ( 2013-10-25 21:02:37 -0600 )edit

Even with the first version you'll get warnings from puppet-lint, due to incompatibility with puppet 2.6:

deric gravatar imagederic ( 2013-10-28 03:26:38 -0600 )edit

Perhaps it is a typo and ntp::install should inherit from ntp::params?

robrwo gravatar imagerobrwo ( 2014-01-29 10:40:19 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2016-02-07 17:32:45 -0600

Henrik Lindberg gravatar image

The phrase "should have no parameters", should be interpreted as "should have no parameters that require a value to be given"; i.e. they must get their parameters either from a default expression in the class definition, or from automatic data binding. If all parameters will get values, then it is possible to derive a class from a parameterized class.

I am not certain this work exactly the same in every puppet version. Here is script to try it out:

class base($base_param = 1) {
  notice "in base base::base_param = $base_param"
class derived($derived_param=2) inherits base {
  $base_param = 2
  notice "in derived base::base_param = $base::base_param"
  notice "in derived derived::derived_param = $derived_param"
  notice "in derived derived::base_param = $base_param"

class { 'base': }
class { 'derived':}

notice "in top scope base::base_param = $base::base_param"
notice "in top scope derived::derived_param = $derived::derived_param"

This should produce the output:

Notice: Scope(Class[Base]): in base base::base_param = 1
Notice: Scope(Class[Derived]): in derived base::base_param = 1
Notice: Scope(Class[Derived]): in derived derived::derived_param = 2
Notice: Scope(Class[Derived]): in derived derived::base_param = 2
Notice: Scope(Class[main]): in top scope base::base_param = 1
Notice: Scope(Class[main]): in top scope derived::derived_param = 2
edit flag offensive delete link more

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


Asked: 2013-10-25 18:50:41 -0600

Seen: 386 times

Last updated: Oct 25 '13