I want to check whether the content of a variable is an odd number. But I need an integer for it.
$ip_array = split($ipaddress, '.')
$odd_ip = $ip_array[3] % 2
if $odd_ip == 1 {
notice("is odd")
}
Is there an easy way to convert a string to integer?
You can do this:
I've taken to using the scanf function in stdlib.
An example of this:
$ram = scanf("${::memorysize_mb}", "%i")
This requires puppet >= 3.7.5
Your code will work exactly as defined; Puppet implicitly converts strings and integers as appropriate for the comparison operator being used.
Puppet 4:
$odd_ip = Integer($ip_array[3]) % 2
Taken from https://github.com/puppetlabs/puppetlabs-apt/pull/743/files