Module: PuppetX::EnterpriseModules::OraInstall::GetHomes
- Included in:
- Facts
- Defined in:
- lib/puppet_x/enterprisemodules/ora_install/get_homes.rb
Overview
Docs
Instance Method Summary collapse
- #cleanup_opatch_residue(homes) ⇒ Object
- #default_database_sid ⇒ Object
- #first_non_root_file(dir) ⇒ Object
- #get_homes(path) ⇒ Object
- #get_orainst_loc ⇒ Object
- #group_for_file(home) ⇒ Object
- #installed_patches(resources = nil) ⇒ Object
- #ora_invdir ⇒ Object
- #oracle_home_for(sid) ⇒ Object
- #oracle_homes(resources = nil) ⇒ Object
- #oratab_content ⇒ Object
- #oratab_exists? ⇒ Boolean
- #oratab_file ⇒ Object
- #os ⇒ Object
- #patches_in_home(oracle_product_home_dir, orainst_dir, resources = nil) ⇒ Object
- #user_for_file(home) ⇒ Object
Instance Method Details
#cleanup_opatch_residue(homes) ⇒ Object
182 183 184 185 186 187 188 189 190 |
# File 'lib/puppet_x/enterprisemodules/ora_install/get_homes.rb', line 182 def cleanup_opatch_residue(homes) # TODO: This is duplicate code from facts.rb. We need to make this more common # Some older versions of Opatch leave files and directories arround # When running opatch often, this causes some issues. This is to make # sure all files created by running Opatch as part of the fact, are remopved basename = Time.now.strftime("%Y-%m-%d_%H-%M-*%p") FileUtils.rm_f("/OraInstall2018#{basename}") homes.each {|home| FileUtils.rm_f("#{home}/cfgtoollogs/opatch/lsinv/lsinventory#{basename}.txt") } end |
#default_database_sid ⇒ Object
11 12 13 |
# File 'lib/puppet_x/enterprisemodules/ora_install/get_homes.rb', line 11 def default_database_sid Hash[*oratab_content.scan(/^(?!#)(.*):(.*):.*$/).flatten].keys.first end |
#first_non_root_file(dir) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/puppet_x/enterprisemodules/ora_install/get_homes.rb', line 65 def first_non_root_file(dir) if Dir.exist?(dir) Dir.new(dir).each { |file| break file if File.stat("#{dir}/#{file}").uid.nonzero? } else nil end end |
#get_homes(path) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/puppet_x/enterprisemodules/ora_install/get_homes.rb', line 77 def get_homes(path) unless path.nil? if File.exist?(path + '/ContentsXML/inventory.xml') file = File.read(path + '/ContentsXML/inventory.xml') doc = REXML::Document.new(file) homes = [] doc.elements.each('/INVENTORY/HOME_LIST/HOME') do |element| # # Skip all entryes that have subelements. # next if element.elements[1] && element.elements[1].name == 'DEPHOMELIST' str = element.attributes['LOC'] name = element.attributes['NAME'] if element.attributes['REMOVED'] == 'T' Puppet.debug "Home #{str} marked as removed in Oracle inventory; skipping for ora_install_homes fact." next end unless str.nil? if str.include? 'plugins' # skip EM agent elsif str.include? 'jdk' # skip EM agent elsif str.include? 'OraPlaceHolderDummyHome' # skip OraPlaceHolderDummyHome else homes << str end end end return homes else return [] end else return [] end end |
#get_orainst_loc ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/puppet_x/enterprisemodules/ora_install/get_homes.rb', line 115 def get_orainst_loc if os == 'windows' begin str = Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\\Oracle').read('inst_loc')[1] return str rescue return '' end else if File.exist?("#{ora_invdir}/oraInst.loc") str = '' output = File.read("#{ora_invdir}/oraInst.loc") output.split(/\r?\n/).each do |item| if item.match(/^inventory_loc/) str = item[14, 50] end end return str else return '' end end end |
#group_for_file(home) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/puppet_x/enterprisemodules/ora_install/get_homes.rb', line 19 def group_for_file(home) # # To run opatch, we need the owner of the grid and oracle directory. The mechanism # we use to get this user, is to fetch the owner of the bin directory in the grid or # oracle home. Sometimes however, these directories also contain files with root as owner. # since root can never be the user of the grid or oracle processen, we skip those. # if os == 'windows' if File.exist?("#{get_orainst_loc}/oraInst.loc") file = File.read("#{get_orainst_loc}/oraInst.loc") file.scan(/inst_group=(.*)/).flatten.first end else a_file = first_non_root_file(home) if a_file gid = File.stat("#{home}/#{a_file}").gid Etc.getgrgid(gid).name else nil end end end |
#installed_patches(resources = nil) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/puppet_x/enterprisemodules/ora_install/get_homes.rb', line 147 def installed_patches(resources = nil) if resources oracle_homes(resources).collect do |oracle_home| patches_in_home(oracle_home, ora_invdir, resources) end.flatten else oracle_homes.collect do |oracle_home| patches_in_home(oracle_home, ora_invdir) end.flatten end end |
#ora_invdir ⇒ Object
212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/puppet_x/enterprisemodules/ora_install/get_homes.rb', line 212 def ora_invdir case os when 'Linux' then '/etc' when 'SunOS' then '/var/opt/oracle' when 'windows' then get_orainst_loc else '/etc' end end |
#oracle_home_for(sid) ⇒ Object
15 16 17 |
# File 'lib/puppet_x/enterprisemodules/ora_install/get_homes.rb', line 15 def oracle_home_for(sid) Hash[*oratab_content.scan(/^(?!#)(.*):(.*):.*$/).flatten].select { |k, _v| k == sid }.values.first end |
#oracle_homes(resources = nil) ⇒ Object
139 140 141 142 143 144 145 |
# File 'lib/puppet_x/enterprisemodules/ora_install/get_homes.rb', line 139 def oracle_homes(resources = nil) if resources resources.map { |_k, v| v.oracle_product_home_dir }.uniq else get_homes(get_orainst_loc) end end |
#oratab_content ⇒ Object
200 201 202 203 204 205 206 |
# File 'lib/puppet_x/enterprisemodules/ora_install/get_homes.rb', line 200 def oratab_content if File.exist?(oratab_file) File.read(oratab_file) else '' end end |
#oratab_exists? ⇒ Boolean
192 193 194 195 196 197 198 |
# File 'lib/puppet_x/enterprisemodules/ora_install/get_homes.rb', line 192 def oratab_exists? if os == 'windows' false else File.exist?(oratab_file) end end |
#oratab_file ⇒ Object
208 209 210 |
# File 'lib/puppet_x/enterprisemodules/ora_install/get_homes.rb', line 208 def oratab_file "#{ora_invdir}/oratab" end |
#os ⇒ Object
73 74 75 |
# File 'lib/puppet_x/enterprisemodules/ora_install/get_homes.rb', line 73 def os Facter.value(:kernel) end |
#patches_in_home(oracle_product_home_dir, orainst_dir, resources = nil) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/puppet_x/enterprisemodules/ora_install/get_homes.rb', line 159 def patches_in_home(oracle_product_home_dir, orainst_dir, resources = nil) if !resources os_user = user_for_file(oracle_product_home_dir) if os_user Dir.chdir(oracle_product_home_dir) do full_command = os == 'windows' ? \ "#{oracle_product_home_dir}\\OPatch\\opatch.bat lspatches -jdk #{oracle_product_home_dir}\\jdk -oh #{oracle_product_home_dir}" : \ "#{oracle_product_home_dir}/OPatch/opatch lspatches -jdk #{oracle_product_home_dir}/jdk -oh #{oracle_product_home_dir} -invPtrLoc #{orainst_dir}/oraInst.loc" raw_list = Puppet::Util::Execution.execute(full_command, :failonfail => true, :uid => os_user, :combine => true ) Puppet.debug "\n#{raw_list}" cleanup_opatch_residue([oracle_product_home_dir]) raw_list.scan(/^(\d+);(.*)$/).collect { |e| { :name => "#{oracle_product_home_dir}:#{e[0]}", :comment => e[1] } } end else [] end else ora_install_homes = Facter.value(:ora_install_homes) || {} patches = ora_install_homes.dig('installed_patches', oracle_product_home_dir) patches.nil? ? [] : patches.collect { |p| { :name => "#{oracle_product_home_dir}:#{p}", :comment => '', :ensure => :present } } end end |
#user_for_file(home) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/puppet_x/enterprisemodules/ora_install/get_homes.rb', line 42 def user_for_file(home) # # To run opatch, we need the owner of the grid and oracle directory. The mechanism # we use to get this user, is to fetch the owner of the bin directory in the grid or # oracle home. Sometimes however, these directories also contain files with root as owner. # since root can never be the user of the grid or oracle processen, we skip those. # if os == 'windows' group = group_for_file(home) users_in_group = `net localgroup #{group}` users = users_in_group.scan(/(^[a-zA-Z]*$)/).flatten users.reject!(&:empty?).reject! { |u| u == 'Members' }.first else a_file = first_non_root_file(home) if a_file uid = File.stat("#{home}/#{a_file}").uid Etc.getpwuid(uid).name else nil end end end |