Search code examples
classinheritancepuppetencapsulationdevops

Puppet access parameters of module through other module


I'm trying to deal with following situation:

class profile:mq {
include rabbitmq
}

class rabbitmq (
$user, $pass, $host ) {
...logic...
}

I would like to use hiera auto lookup to fill in parameters in rabbitmq through profile::mq class (eg profile::mq:rabbitmq::user: "value", not rabbitmq::user: "value") My guess is to encapsulate rabbitmq but not sure how to do it in puppet.


Solution

  • Automated data binding: good plan.

    It simply doesn't work the way you propose, however. The hiera keys by which a given class looks up its parameter values depend only on the class and parameter names. They are independent of the locus of any and all declarations of that class. It cannot be otherwise, because multiple declarations of the same class may be evaluated for the same target node, and -- because classes are singletons -- they all declare the same class (instance).

    You may be able to achieve what you're after by putting the rabbitmq parameter values in a profile-specific level of your Hiera hierarchy. That doesn't feel quite right to me, but it may serve well enough for your purposes.