Class: ForemanAnsible::FactParser

Inherits:
FactParser
  • Object
show all
Includes:
OperatingSystemParser
Defined in:
app/services/foreman_ansible/fact_parser.rb

Overview

Override methods from Foreman app/services/fact_parser so that facts representing host properties are understood when they come from Ansible.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from OperatingSystemParser

#debian_os_major_sid, #local_os, #new_os, #operatingsystem, #os_description, #os_major, #os_minor, #os_name, #os_release, #os_release_name

Constructor Details

#initialize(facts) ⇒ FactParser

Returns a new instance of FactParser.



10
11
12
# File 'app/services/foreman_ansible/fact_parser.rb', line 10

def initialize(facts)
  @facts = HashWithIndifferentAccess.new(facts[:ansible_facts])
end

Instance Attribute Details

#factsObject (readonly)

Returns the value of attribute facts.



8
9
10
# File 'app/services/foreman_ansible/fact_parser.rb', line 8

def facts
  @facts
end

Instance Method Details

#architectureObject



17
18
19
20
# File 'app/services/foreman_ansible/fact_parser.rb', line 17

def architecture
  name = facts[:ansible_architecture] || facts[:facter_architecture]
  Architecture.where(:name => name).first_or_create if name.present?
end

#domainObject



28
29
30
31
32
# File 'app/services/foreman_ansible/fact_parser.rb', line 28

def domain
  name = detect_fact([:ansible_domain, :facter_domain,
                      :ohai_domain, :domain])
  Domain.where(:name => name).first_or_create if name.present?
end

#environmentObject

Don’t do anything as there’s no env in Ansible



15
# File 'app/services/foreman_ansible/fact_parser.rb', line 15

def environment; end

#get_facts_for_interface(interface) ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'app/services/foreman_ansible/fact_parser.rb', line 54

def get_facts_for_interface(interface)
  interface.tr!('-', '_') # virbr1-nic -> virbr1_nic
  interface_facts = facts[:"ansible_#{interface}"]
  ipaddress = ip_from_interface(interface)
  ipaddress6 = ipv6_from_interface(interface)
  HashWithIndifferentAccess[
    interface_facts.merge(:ipaddress => ipaddress,
                          :ipaddress6 => ipaddress6)
  ]
end

#get_interfacesObject

Move ansible’s default interface first in the list of interfaces since Foreman picks the first one that is usable. If ansible has no preference otherwise at least sort the list.

This method overrides app/services/fact_parser.rb on Foreman and returns an array of interface names, [‘eth0’, ‘wlan1’, etc…]



44
45
46
47
48
49
50
51
52
# File 'app/services/foreman_ansible/fact_parser.rb', line 44

def get_interfaces # rubocop:disable Naming/AccessorMethodName
  pref = facts[:ansible_default_ipv4] &&
         facts[:ansible_default_ipv4]['interface']
  if pref.present?
    (facts[:ansible_interfaces] - [pref]).unshift(pref)
  else
    ansible_interfaces
  end
end

#ipmi_interfaceObject



65
# File 'app/services/foreman_ansible/fact_parser.rb', line 65

def ipmi_interface; end

#modelObject



22
23
24
25
26
# File 'app/services/foreman_ansible/fact_parser.rb', line 22

def model
  name = detect_fact([:ansible_product_name, :facter_virtual,
                      :facter_productname, :facter_model, :model])
  Model.where(:name => name.strip).first_or_create if name.present?
end

#support_interfaces_parsing?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'app/services/foreman_ansible/fact_parser.rb', line 34

def support_interfaces_parsing?
  true
end