On Friday, May 3, 2013 4:16:25 AM UTC-5, christian...@gmail.com wrote:
>
> Hi,
> a question regarding combining *inherit* and *include*: I have 
> variable(s) defined in a father class and child classes should access these 
> - but there should always be the possibility to override the default value. 
> Let's assume this scenario:
>
> There's a module "module_x" and these directories: 
> $moduledir/module_x/manifests/ and there's an "init.pp" with this content:
>
> class module_x {
> $var = 'value'
>
> include module_x::child
> include module_x::another_child
> include module_x::another_child2
> include module_x::another_child3
> ...    
> }
>
>
>  Class "module_x::child" in file "child.pp" should be able to use "$var" 
> with its default value - but should also be allowed to override it.
>


Subclasses can never 'override' ancestor class variables.  They can 
partially *hide* them within their own scope by declaring a same-named 
local variable, but that has no effect on what the parent class or any 
other sees as the value of the parent-class variable.

The purpose of class inheritance in Puppet is to permit overriding of *resource 
parameters* of resources declared by the parent class.  It has a 
sometimes-useful side effect of causing the parent class to be evaluated 
before any part of the child class, notably including the child class's 
parameter list, if any.  If you're using class inheritance for any other 
purpose then you are misusing it (and it is probably not doing what you 
think it's doing).

 

> It would look like this:
>
> class module_x::child inherits module_x {
> // wants to use a default value for $var but should be able to override it.
> }
>
>
>

That creates a circular evaluation dependency: class module_x must be 
evaluated before class module_x::child (because the latter inherits the 
former), but class 'module_x::child' must be evaluated as the first step in 
evaluating class module_x (on account of 'include'ing it).  I'm not sure 
what Puppet will actually do with that, but it's fundamentally wrong.

 

> Question: Is there somehow a problem that class "child" inherits class 
> "module_x" *with all its many includes*?
>
>
There is a problem that class module_x::child inherits class module_x with 
its specific include of class module_x::child.  I see no reason why any of 
the other includes would be an issue.

You have a fundamental problem with your design approach.  It will not work 
as you envision, so you need to take a step back and devise a new way to go 
about it.  If you explain better what you are trying to achieve then we may 
be able to help you more.


John

-- 
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 puppet-users+unsubscr...@googlegroups.com.
To post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to