Andreas Kuntzagk <[email protected]> wrote:
> I want some config depending on memorysize.
>
> What I tried was
> if ($memorysize >= 256 * 1024*1024) {
> ...
> }
>
> But this fails because $memorysize is a string (and contains a "G")
> and can't be compared to an int.
>
> Are all facts strings? How do I work with numbers?
Typical problem. Not to mention that you happen to have "G" but that
could very easily be "M". Here's my workaround for that, which I use
for calculations to then set some sysctl.conf values accordingly :
# This is ugly, but very useful to get a standard kiB total RAM
# to base further calculations upon. Note that we get a string
$mem = inline_template("<%
mem,unit = scope.lookupvar('::memorysize').split
mem = mem.to_f
# Normalize mem to KiB
case unit
when nil: mem *= (1<<0)
when 'kB': mem *= (1<<10)
when 'MB': mem *= (1<<20)
when 'GB': mem *= (1<<30)
when 'TB': mem *= (1<<40)
end
%><%= mem.to_i %>")
Here's an example of how I then use it :
# kernel.shmmax
if $shmmax {
$shmmax_final = $shmmax
} else {
if $oracle {
# For non-shm half the RAM for <= 4G, 2G otherwise
if $mem <= 4294967296 {
$shmmax_final = $mem / 2
} else {
$shmmax_final = $mem - 2147483648
}
} else {
$shmmax_final = $mem
}
}
HTH,
Matthias
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.