Ask Your Question

setting values with hiera in subclasses

asked 2014-04-11 11:21:02 -0500

deric gravatar image

updated 2014-04-11 13:40:39 -0500

I'd like to define shared parameters just once in parent class and then reuse them in other classes. However if I set

myParent::foo: 'bar'

it's not propagated to child class unless I call explicitly hiera('myParent::foo')

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2014-04-11 13:08:53 -0500

deric gravatar image

Just note to self, or for someone solving similar issue, puppet parameters can't be defined directly in parent class, if you want to inherit them:

class myParent {
    foo = 'foo value'
    bar = 'bar value'  

class child(
    foo = $myParent::foo,
) inherits myParent {}

defining value in hiera

myParent::foo: 'something'

won't propagate to child class. unless you initialize child's value from hiera foo = hiera('myParent::foo', $myParent::foo)

However it will work when parameters are in () like this:

class myParent( 
    foo = 'foo value',
    bar = 'bar value'  
) inherits myParent { }
edit flag offensive delete link more

answered 2014-04-12 16:55:34 -0500

ffrank gravatar image

"Shared" parameters as you say are not possible. The child's parameter will hide the value passed to the parent.

You should indeed abstain from declaring the parameter again for the inheriting class. This may imply that you need to explicitly declare both parent and child class for use.

class {
  "parent": shared_param => "foo";
  "child": child_only_param => "bar";

If you provide more information on the problem you're actually trying to solve, we might be able to suggest a cleaner approach altogether.

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: 2014-04-11 11:21:02 -0500

Seen: 417 times

Last updated: Apr 12 '14