Hi,
Sorry for this late answer. I had time to think about this question of "design".
On 07/12/2015 17:18, jcbollinger wrote:
> I think the specific conditions are irrelevant to the main thrust of my
> position. The fact that your code and data would need to comply with a
> relatively complex set of conditions for what you propose to be workable at
> all is one of my primary arguments. I predict that taking on such a set of
> extra requirements will cause you grief, more likely sooner than later, and
> I urge you to devise another way to accomplish your objective.
>
> If you insist on proceeding in this general direction, however, then I'd
> suggest employing a variation on the Params Class pattern. Create a class
> ::moda::params and give it a parameter or ordinary class variable
> $::moda::params::param that will serve both as the (definite)
> initialization value for $::moda::param and as the default value for
> $::modb::param. This will require that $::moda::param be made an ordinary
> class variable instead of a class parameter, so that it can never take a
> value different from $::moda::params::param. It will also require that
> class ::modb inherit directly or indirectly from class ::moda::params. In
> Puppet 4, $::moda::params::param can receive its value in any way you see
> fit, including automated data binding (if you opt to make
> $::moda::params::param a class parameter), but you would create an
> evaluation-order dependency if every you used a resource-like declaration
> of it, either directly or via an ENC. Class ::moda::params would avoid
> declaring any resources so that declaring it (as classes ::moda and ::modb
> would both need to ensure happens) will not directly affect the target
> node's state.
>
> If you're following closely you will observe that that solves the problem
> by adding a layer of indirection. You may also recognize that class
> inheritance across module boundaries is considered poor practice by many;
> this should be taken as further support for my argument that your proposed
> modules are too tightly coupled.
Ok, so I have thought about the "params" design in Puppet 4, and indeed
finally I'm wondering if something like that could be a good idea:
a) For a module moda, I use a class moda::params which has parameters and an
_empty_ body like this:
class moda::params (
String[1] $var1,
Array[String[1], 1] $var2,
String[1] $var3,
# etc.
) {
# The body of this class if completely empty!
}
This class above contains all parameters needed for the module moda.
b) Then I use ./moda/function/data.pp to set relevant default values for
the parameters of the class "moda::params":
function moda::data {
# Some code to chose relevant default values of $var1, $var2 etc.
$var1 = ...
$var1 = ...
# etc.
{
moda::params::var1 => $var1,
moda::params::var1 => $var2,
# etc.
}
}
b) And for any public class of moda, I create systematically a class without
parameter and I use the parameters of moda::params like this:
# moda::foo is a public class fo moda.
class moda::foo {
# Class without parameter, we use variables in moda::params instead.
require '::moda::params'
$var1 = ::moda::params::var1
$var2 = ::moda::params::var2
# etc.
# some code...
}
And now, if I have another module modb which depends on moda so that I
would like some default modb values are equal to some moda values, I can
create the module modb with the same principle described above _and_ :
a) I declare moda as dependency of modb in the metadata.json file of modb:
"dependencies": [
{"name":"puppetlabs-stdlib","version_requirement":">= 4.6.0"},
{"name":"me-moda","version_requirement":">= 0.1.0"}
]
}
b) and in the ./modb/function/data.pp of modb, I do something like that:
function modb::data {
require '::moda::params'
# I retrieve some variables of moda
$var1 = ::moda::params::var1
$var2 = ::moda::params::var2
{
# And for some variables of modb, I use variable of moda as default values.
modb::params::var1_modb => $var1,
modb::params::var2_modb => $var2,
modb::params::var3_modb => 'foo'
# etc.
}
}
Is this pattern "correct"? After thinking, it seems to me a good way to
handle data dependency between modules but I'm really not a puppet expert
and I really appreciate any remark from you John and/or from any other
puppet expert. ;)
Thanks in advance.
--
François Lafont
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/568A0482.4060904%40free.fr.
For more options, visit https://groups.google.com/d/optout.