質問

How can I pass value from inherited class to base class using puppet?

You can see below a simplified code for my trials.

class executor::app($base_dir = "/usr/local",
    $run_command  = undef,
    $prefix_naming  = undef) {

}

class app1(
    $base_dir = ::app1::params::base_dir,
    $prefix_naming  = "reader",
    $run_command  = " ") inherits executor::app{
}
役に立ちましたか?

解決

OK, for starters lets assume you have these classes in module format. If not, then that should be the first order of business.

Second, avoid inheritance. There is almost always a better way to do it. Especially don't inherit across modules. About the only time I can think it's useful is for defaulting class parameters.

The base_dir on class app1 will not get the default unless the class inherits cea::params::base_dir (leading :: not needed). Again, across modules shouldn't be done. app1::params much better -- or just put in a sane default and eliminate the need to inherit parameters all together.

For your actual question, if you want to get a variable in another class you can just reference it. Keep in mind that puppet doesn't guarantee compile order so you should tell it to evaluate the other class first:

class executor::app {
  Class['app1'] -> Class['executor::app']
  $other_app_var = $app1::base_dir
}

Or throw this data in hiera and look up the value.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top