Module: ForemanAnsible::OperatingSystemParser
- Included in:
- FactParser
- Defined in:
- app/services/foreman_ansible/operating_system_parser.rb
Overview
Methods to parse facts related to the OS
Instance Method Summary collapse
- #debian_os_major_sid ⇒ Object
- #local_os(args) ⇒ Object
- #new_os(args) ⇒ Object
- #operatingsystem ⇒ Object
- #os_description ⇒ Object
- #os_major ⇒ Object
- #os_minor ⇒ Object
- #os_name ⇒ Object
- #os_release ⇒ Object
- #os_release_name ⇒ Object
Instance Method Details
#debian_os_major_sid ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/services/foreman_ansible/operating_system_parser.rb', line 30 def debian_os_major_sid case facts[:ansible_distribution_major_version] when /wheezy/i '7' when /jessie/i '8' when /stretch/i '9' when /buster/i '10' end end |
#local_os(args) ⇒ Object
20 21 22 |
# File 'app/services/foreman_ansible/operating_system_parser.rb', line 20 def local_os(args) @local_os = Operatingsystem.where(args).first end |
#new_os(args) ⇒ Object
24 25 26 27 28 |
# File 'app/services/foreman_ansible/operating_system_parser.rb', line 24 def new_os(args) return @new_os if @new_os.present? @new_os = Operatingsystem.new(args.merge(:description => os_description)) @new_os if @new_os.valid? && @new_os.save end |
#operatingsystem ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/services/foreman_ansible/operating_system_parser.rb', line 6 def args = { :name => os_name, :major => os_major, :minor => os_minor } args[:release_name] = os_release_name if os_name == 'Debian' || os_name == 'Ubuntu' return @local_os if local_os(args).present? return @new_os if new_os(args).present? logger.debug do 'Ansible facts parser: No OS could be created with '\ "os_name='#{os_name}' os_major='#{os_major}' "\ "os_minor='#{os_minor}': "\ "#{@new_os.errors if @new_os.present?}" end nil end |
#os_description ⇒ Object
88 89 90 91 92 93 94 |
# File 'app/services/foreman_ansible/operating_system_parser.rb', line 88 def os_description if facts[:ansible_os_family] == 'Windows' facts[:ansible_os_name].strip || facts[:ansible_distribution].strip else facts[:ansible_lsb] && facts[:ansible_lsb]['description'] end end |
#os_major ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'app/services/foreman_ansible/operating_system_parser.rb', line 48 def os_major if os_name == 'Debian' && facts[:ansible_distribution_major_version][%r{\/sid}i] debian_os_major_sid else facts[:ansible_distribution_major_version] || facts[:ansible_lsb] && facts[:ansible_lsb]['major_release'] || (facts[:version].split('R')[0] if os_name == 'junos') end end |
#os_minor ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/services/foreman_ansible/operating_system_parser.rb', line 64 def os_minor _, minor = os_release&.split('.', 2) || (facts[:version].split('R') if os_name == 'junos') # Until Foreman supports os.minor as something that's not a number, # we should remove the extra dots in the version. E.g: # '6.1.7601.65536' becomes '6.1.760165536' if facts[:ansible_os_family] == 'Windows' minor, patch = minor.split('.', 2) patch.tr!('.', '') minor = "#{minor}.#{patch}" end minor || '' end |
#os_name ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'app/services/foreman_ansible/operating_system_parser.rb', line 78 def os_name if facts[:ansible_os_family] == 'Windows' facts[:ansible_os_name].tr(" \n\t", '') || facts[:ansible_distribution].tr(" \n\t", '') else facts[:ansible_distribution] || facts[:ansible_lsb] && facts[:ansible_lsb]['id'] end end |
#os_release ⇒ Object
59 60 61 62 |
# File 'app/services/foreman_ansible/operating_system_parser.rb', line 59 def os_release facts[:ansible_distribution_version] || facts[:ansible_lsb] && facts[:ansible_lsb]['release'] end |
#os_release_name ⇒ Object
43 44 45 46 |
# File 'app/services/foreman_ansible/operating_system_parser.rb', line 43 def os_release_name return '' if os_name != 'Debian' && os_name != 'Ubuntu' facts[:ansible_distribution_release] end |