Class: ForemanAnsible::OverrideResolver

Inherits:
Object
  • Object
show all
Defined in:
app/services/foreman_ansible/override_resolver.rb

Overview

Service which resolves override values for hosts

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, variable_ids = []) ⇒ OverrideResolver

Returns a new instance of OverrideResolver.

Raises:

  • (Foreman::Exception)


6
7
8
9
10
11
12
13
14
# File 'app/services/foreman_ansible/override_resolver.rb', line 6

def initialize(host, variable_ids = [])
  raise(Foreman::Exception.new('OverrideResolver needs a host to resolve overrides')) unless host
  @ansible_variables = if variable_ids.empty?
                         AnsibleVariable.where(:ansible_role_id => host.all_ansible_roles, :override => true)
                       else
                         AnsibleVariable.where(:id => variable_ids, :override => true)
                       end
  @overrides = @ansible_variables.values_hash(host).raw
end

Instance Attribute Details

#ansible_variablesObject (readonly)

Returns the value of attribute ansible_variables.



4
5
6
# File 'app/services/foreman_ansible/override_resolver.rb', line 4

def ansible_variables
  @ansible_variables
end

#overridesObject (readonly)

Returns the value of attribute overrides.



4
5
6
# File 'app/services/foreman_ansible/override_resolver.rb', line 4

def overrides
  @overrides
end

Instance Method Details

#resolve(ansible_variable) ⇒ Object



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

def resolve(ansible_variable)
  override = @overrides[ansible_variable.id]
  return unless override
  override[ansible_variable.key]
end