On 07/13/2012 06:41 PM, no-re...@cfengine.com wrote:
> 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? :)
> 

Should cfengine detect that the variable has not been resolved and use the 
default value?


-- 
********************************************************************
*  Bas van der Vlies                    e-mail: b...@sara.nl       *
*  SARA - Academic Computing Services   Amsterdam, The Netherlands *
********************************************************************



Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to