On May 20, 10:20 am, Carles Amigó <[email protected]> wrote:
> Hi,
>
> I'm trying to pass a parameter different from the default to the child
> of a parametrized class with inheritance,
I would not recommend mixing class inheritance with parameterized
classes.
As a separate matter, I would recommend to most people to avoid
parameterized classes altogether.
> but the inherited code from
> the parent class doesn't seem to be taking the correct parameter.
>
> For example, in the following code:
>
> class parent ( $foo = "bar" ) {
> notice("parent: foo is $foo ")
>
> }
>
> class child ( $foo = "bar" ) inherits parent {
> notice("child: foo is $foo ")
>
> }
>
> class { "child": foo => "test" }
>
> I would expect the following result:
>
> notice: Scope(Class[Parent]): parent: foo is test
> notice: Scope(Class[Child]): child: foo is test
>
> I'm getting the following one instead:
>
> notice: Scope(Class[Parent]): parent: foo is bar
> notice: Scope(Class[Child]): child: foo is test
>
> Is that the correct behaviour?
"Correct" is such a nuanced word. I don't know whether the observed
behavior is by design, but I don't find it surprising. I would not
have found your expected behavior surprising either, however.
You may be able to achieve your desired result like this:
class { "parent": foo => "test" }
class { "child": foo => "test" }
That is, it is safe to include both a class and one of its subclasses
in the same manifest. Do be aware, however, that you should create
subclasses *only* to override superclass resource properties. And
with parameterized classes, you can achieve an equivalent result via
class parameters instead.
If you want a class that declares all the resources of another, plus
more, then have one class "include" the other instead of inheriting
it. Except don't do that with parameterized classes: Puppet Labs
recommends against it, and there are practical reasons to avoid doing
so.
John
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.