On Monday, May 19, 2014 6:45:56 PM UTC-5, Brian Mathis wrote:
>
> I'm seeing this issue with the current version of stdlib. When getting
> numeric data from hiera, or performing math on a variable, validate_re()
> fails when using the following regex:
> '[0-9]+'
>
>
Fascinating.
> Here are some test cases:
>
> Getting data from hiera
> # Hiera data:
> # ---
> # testvalue: 1234
>
> FAIL:
> $myvar = hiera('testvalue')
> validate_re( $myvar, '[0-9]+' )
>
> Performing math
> OK:
> $var = 1000
> validate_re( $var, '[0-9+]' )
>
> FAIL:
> $var2 = 2000 + 1
> validate_re( $var2, '[0-9+]' )
>
> I've had to resort to quoting variables in validate_re, like this:
> OK:
> $var3 = 3000 + 1
> validate_re( "${var3}", '[0-9+]' )
>
> However puppet-lint complains about having only a variable inside
> double-quotes, so I'm considering solving this with the very ugly:
> validate_re( "X${var3}", 'X[0-9+]' )
>
>
Yet your solution using "${var3}" is perfectly good thing to do to convert
a variable of uncertain type to a string. I'd tell puppet-lint to go play
in a clothes dryer.
Alternatively, you could try this instead:
if not is_integer(${var3}) or (${var3} < 0) {
validate_re( ${var3}, '[0-9]+')
}
John
--
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/ff0438de-833c-4207-a605-5cc82c427efb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.