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
rubocop:enable AbcSize.
-
#os_major ⇒ Object
rubocop:disable AbcSize, CyclomaticComplexity, PerceivedComplexity.
-
#os_minor ⇒ Object
rubocop:disable AbcSize.
- #os_name ⇒ Object
-
#os_release ⇒ Object
rubocop:enable AbcSize, CyclomaticComplexity, PerceivedComplexity.
- #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
rubocop:enable AbcSize
92 93 94 95 96 97 98 |
# File 'app/services/foreman_ansible/operating_system_parser.rb', line 92 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
rubocop:disable AbcSize, CyclomaticComplexity, PerceivedComplexity
49 50 51 52 53 54 55 56 57 58 |
# File 'app/services/foreman_ansible/operating_system_parser.rb', line 49 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
rubocop:disable AbcSize
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/services/foreman_ansible/operating_system_parser.rb', line 67 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
81 82 83 84 85 86 87 88 89 |
# File 'app/services/foreman_ansible/operating_system_parser.rb', line 81 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
rubocop:enable AbcSize, CyclomaticComplexity, PerceivedComplexity
61 62 63 64 |
# File 'app/services/foreman_ansible/operating_system_parser.rb', line 61 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 |