diff --git a/app/models/operatingsystem.rb b/app/models/operatingsystem.rb index 0d97e87e2907..9fa3f911e4b9 100644 --- a/app/models/operatingsystem.rb +++ b/app/models/operatingsystem.rb @@ -170,7 +170,11 @@ def self.find_by_to_label(str) os = find_by_description(str.to_s) return os if os a = str.split(" ") - b = a[1].split('.') if a[1] + if a[0] =~ /ubuntu/i + b = a[1], nil if a[1] + else + b = a[1].split('.') if a[1] + end cond = {:name => a[0]} cond[:major] = b[0] if b && b[0] cond[:minor] = b[1] if b && b[1] diff --git a/app/services/foreman_ansible/operating_system_parser.rb b/app/services/foreman_ansible/operating_system_parser.rb index 529af5884d77..fc0acb062bcd 100644 --- a/app/services/foreman_ansible/operating_system_parser.rb +++ b/app/services/foreman_ansible/operating_system_parser.rb @@ -55,6 +55,8 @@ def os_major (facts[:ansible_distribution_major_version][%r{\/sid}i] || facts[:ansible_distribution_major_version] == 'n/a') debian_os_major_sid + elsif os_name == 'Ubuntu' + facts[:ansible_distribution_major_version] else facts[:ansible_distribution_major_version] || facts[:ansible_lsb] && facts[:ansible_lsb]['major_release'] || @@ -68,8 +70,12 @@ def os_release end def os_minor - _, minor = os_release&.split('.', 2) || + if os_name == 'Ubuntu' + minor = nil + else + _, minor = os_release&.split('.', 2) || (facts[:version].split('R') if os_name == 'junos') + end # 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' diff --git a/app/services/foreman_chef/fact_parser.rb b/app/services/foreman_chef/fact_parser.rb index b9a30e869c21..d370c86dc037 100644 --- a/app/services/foreman_chef/fact_parser.rb +++ b/app/services/foreman_chef/fact_parser.rb @@ -9,6 +9,8 @@ def operatingsystem # if we have no release information we can't assign OS properly (e.g. missing redhat-lsb) if release.nil? major, minor = 1, nil + elsif os_name == 'Ubuntu' + major, minor = release, nil else major, minor = release.split('.') end diff --git a/app/services/katello/rhsm_fact_parser.rb b/app/services/katello/rhsm_fact_parser.rb index 9ae57a257207..512797918b76 100644 --- a/app/services/katello/rhsm_fact_parser.rb +++ b/app/services/katello/rhsm_fact_parser.rb @@ -55,7 +55,13 @@ def operatingsystem return nil if name.nil? || version.nil? os_name = distribution_to_puppet_os(name) - major, minor = version.split('.') + version_splits = version.split('.') + if name =~ /ubuntu/i + major = "#{version_splits[0]}.#{version_splits[1]}" + minor = version_splits[2] if version_splits.length == 3 + else + major, minor = version_splits + end unless facts['ignore_os'] os_attributes = {:major => major, :minor => minor || '', :name => os_name} diff --git a/app/services/puppet_fact_parser.rb b/app/services/puppet_fact_parser.rb index b9fa40704ad5..3a3a63bd6758 100644 --- a/app/services/puppet_fact_parser.rb +++ b/app/services/puppet_fact_parser.rb @@ -5,9 +5,14 @@ def operatingsystem orel = os_release.dup if orel.present? - major, minor = orel.split('.', 2) - major = major.to_s.gsub(/\D/, '') - minor = minor.to_s.gsub(/[^\d\.]/, '') + if os_name =~ /ubuntu/i + major = os_major_version + minor = os_minor_version + else + major, minor = orel.split('.') + major = major.to_s.gsub(/\D/, '') + minor = minor.to_s.gsub(/[^\d\.]/, '') + end args = {:name => os_name, :major => major, :minor => minor} os = Operatingsystem.find_or_initialize_by(args) if os_name[/debian|ubuntu/i] || os.family == 'Debian' @@ -227,6 +232,14 @@ def os_name raise(::Foreman::Exception.new("invalid facts, missing operating system value")) end + def os_major_version + facts.dig(:os, :release, :major) + end + + def os_minor_version + facts.dig(:os, :release, :minor) + end + def os_release case os_name when /(windows)/i