I am writing a module to manage a product w/ a few components. There are a
few parameters that are common to most of the components but there may be
cases where it would be useful to override the values from one component to
another. I can see two ways to handle this, 1. inheritance and 2. include.
*Inheritance*
While this is pretty easy to read Puppetlabs recommends against using
inheritance in most cases. Is this a good case? Also in this case does it
make sense to duplicate the params in the child class but reference the
parent for the defaults for clarity or is it considered correct to inherit
and let things be?
class product (
$param1,
$param2,
) {}
class product::thing1 (
$thingparam1
) inherits product {
}
# OR
class product::thing1 (
$thingparam1,
$param1 = $parent::param1,
$param2 = $parent::param2, # Is this considered best practice or should I
rely on the "inherits" statement to hint to the reader that there are more
params?
) inherits product {
if $param1 {
# do something
}
file{'/tmp/foo':
content => inline_template("This is a test <%= @param2 %>...")
}
}
*Include*
The real difference i see here is that you'd have to be sure to include
product in product::thing1 and variables won't be in the local scope.
class product::thing1 (
$thingparam1,
) {
include product
if $::product::param1 {
# do something
}
file{'/tmp/foo':
content => inline_template("This is a test <%=
scope['::product::param2'] %>...")
}
Which of these is the more correct/preferred method or have I missed other
options?
Thanks,
-Alan
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/252a6d03-1a97-4208-bf4d-f8203f8f637do%40googlegroups.com.