I’m working on a chef recipe that will pull down a program installer depending on the memory total in a linux server. If the memory total is 8GB or more install …. if the memory is less than 8GB then install … . Does anybody happen to know how to script this?
Chef is ruby based.
Within my chef recipes I have attempted the following, but had no success.
puts "***** Linux server node['platform_family']=#{node['platform_family']}"
puts "***** Linux server node['memory.total']=#{node['memory.total']}"
# -------------------------------------------------------------------------------
puts "*****#{node['platform_family']}"
puts "*****#{node['memory.total']}"
if node['platform_family'] == 'debian' && node['memory.total'] >= 7000000
remote_file '/tmp'
source 'local file'
action :create
end
elsif
remote_file '/tmp'
source 'external file'
action :create
end
2
Answers
If you’re only ever going to use this recipe in Linux, then this method will work:
Different OSes report this value differently and not always in the same format though. So if you want to support any system platform (just in case this has a use for someone not using Linux) this would be a far better option:
The
remote_file
resource can written in a better way (once) if we can compute the value ofsource
property beforehand. Also since you have shown comparison ofnode['platform_family']
, it appears you would need to match for OS families other thandebian
as well.Below code will match for
platform_family
and['memory']['total']
and set a value that we can use with thesource
property.Note that I’m using ternary operator as an alternative to
if
/else
withinwhen
condition ofcase
statement.