Puppet – Custom Facts – Check SAP Oracle version

REMARK – use *** ¬†puppet facts find <servername> –render-as yaml | grep sap_ora

Make a custom fact (ruby code) that determins the Oracle version SAP is using.

Under  modules tree /modules/<module_name>/lib/oracleversion.rb

 

Facter.add("sap_oracleversion") do
 confine :operatingsystem => 'SLES'
 if Facter.value(:sapprepsids) != nil
 setcode do
 result = "none"
 sapprep_sid = Facter.value(:sapprepsids)
 first_sid = sapprep_sid.to_s.split(',')[0]
 second_sid = sapprep_sid.to_s.split(',')[1]
 third_sid = sapprep_sid.to_s.split(',')[2]
 sid_big = first_sid[1...-1]
 sid_small = sid_big.downcase
 sidadm_user_not_exists = Facter::Util::Resolution.exec('/usr/bin/id -u ' + sid_small + 'adm' + ' > /dev/null 2>&1; echo $?')

 if sidadm_user_not_exists == "0"
 cmd = 'sudo -i -u ' + sid_small + 'adm' + ' printenv LOGNAME'
 oracle_homeuser = Facter::Util::Resolution.exec(cmd)
 if output = Facter::Util::Resolution.exec('sudo -i -u ' + sid_small + 'adm' + ' printenv ORACLE_HOME | awk -F "/" \' { print $4 } \' | cut -c1-2')
 result = "unknown"
 result = "11" if output == "11"
 result = "12" if output == "12"
 end
 end
 cmd
 result
 end
 end
end


Sources:

# http://stackoverflow.com/questions/19637677/ruby-remove-characters-from-a-string
# http://stackoverflow.com/questions/22495504/using-a-facter-fact-within-a-fact-for-command-execution
# https://gist.github.com/epleterte/3740319
# http://www.codecodex.com/wiki/Replace/remove_character_in_a_String