Forum: CFEngine Help
Subject: Re: Defining default vars
Author: sauer
Link to topic: https://cfengine.com/forum/read.php?3,23704,23715#msg-23715
I do this with two bundles. I use one bundle to define one or two parameters -
a default value and a commonly-named "special" value:
bundle common blahblah_vars {
vars:
any::
"default_thingie" string => "default";
class1::
"special_thingie" string => "special";
class2::
"special_thingie" string => "not-so-special";
classes:
"has_special_thingie" expression => isvariable("special_thingie");
}
And then I have my "real" bundle set the local variable depending upon whether
or not the "has_special" class is set:
bundle agent blahblah_real {
vars:
has_special_thingie::
"thingie" string => "$(blahblah_vars.special_thingie)";
!has_special_thingie::
"thingie" string => "$(blahblah_vars.default_thingie)";
}
Using a common bundle to define both the class and the variables makes it sure
that, by the time I need to use the variables, a the "default" and "special"
values will definitely have been assessed, and the class which controls which
one I'll use will also have stabilized. It has to be a common bundle,
unfortunately, so that the class is visible from the other bundle (if only the
use of period in class expressions wasn't synonymous with "and" so we could
reference foreign classes like with variables). The alternative would be to
use a third intermediate common bundle just for the class definition if the var
bundle needs to be an agent (or whichever), but that's more complexity.
I use this basic paradigm a lot, but would love to just have parametrized
bundles which allow for default values used when a parameter is not specified.
This solution is kind of an ugly workaround - but I like to think of it as the
most elegant possible ugly workaround. :)
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine