I wrote a "memorysize_mb" fact to solve this problem; this ensures the number returned is only an integer value.
$ cat memorysize_mb.rb
require 'facter'
Facter.add("memorysize_mb") do
confine :kernel => :Linux
ram = 0
# Steal linux's meminfo
File.open( "/proc/meminfo" , 'r' ) do |f|
f.grep( /^MemTotal:/ ) { |mem|
ram = mem.split( / +/ )[1].to_i / 1024
}
end
setcode do
ram
end
end
On 03/08/2010 03:12 PM, John wrote:
> Ok some more investigation turned up some more questions.
> So it seems memorysize is returned with a unit of measurement suffix
> added to it....
>
> My question to the puppet mailing list would be.
>
> How would you use memory size fact in puppet while keeping in mind
> that we could be talking MB or GB?
>
> I need to make decisions based on the amount of memory available.
> The whole scaling unit of measurement is kind of annoying though. /
> proc/meminfo normally reports as kb doesnt it?
>
> On Mar 8, 11:06 am, John Cesario <[email protected]> wrote:
>> On version 0.25.4 for both server and client.
>>
>> Trying to do some logic around the $memorysize fact.
>>
>> if ($memorysize > 15360) and ($memorysize < 112640) {
>> $tmpfs_size = "6G"
>> } else {
>> $tmpfs_size = "8G"
>> }
>>
>> Returns
>>
>> err: Could not retrieve catalog from remote server: Error 400 on SERVER:
>> comparison of String with 15360 failed at
>> /etc/puppet/modules/mysql/manifests/virtual_tmpdir.pp:13 on node foo.bar
>
signature.asc
Description: OpenPGP digital signature
