Forum: CFEngine Help Subject: Re: Using defaults promises Author: zzamboni Link to topic: https://cfengine.com/forum/read.php?3,26464,26465#msg-26465
Neil, The default value kicks in only when the variable in question is not defined. In your example, "version" *is* defined - although because the corresponding hash element does not exist, you get the raw string, without any interpolation. But this is still a valid, defined string value, so the default value is not used. However, CFEngine default values can also be conditioned on certain patterns, using the if_match_regex attribute: https://cfengine.com/manuals/cf3-Reference#if_005fmatch_005fregex-in-defaults Using if_match_regex, you could check if the variable starts with a dollar sign, which would most likely indicate that it's a non-interpolated value. So this change makes your example work: defaults: "version" string => "Not provided", if_match_regex => "(^$)|(^\$.*$)"; In this case the default value kicks in if the string is empty or if it starts with a dollar sign. Neat isn't it? :) _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine