Class: ForemanAnsibleDirector::Generators::VariableGenerator

Inherits:
Object
  • Object
show all
Defined in:
app/lib/foreman_ansible_director/generators/variable_generator.rb

Class Method Summary collapse

Class Method Details

.generate(host:, resolved_host_content:) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/lib/foreman_ansible_director/generators/variable_generator.rb', line 7

def generate(host:, resolved_host_content:)
  variables = {}

  resolved_host_content.each do |content_assignment|
    consumable = content_assignment[:cuv]
    next unless consumable
    resolved = consumable.ansible_variables.values_hash(host)
    role_variables = consumable.ansible_variables.to_a

    if consumable.is_a? ForemanAnsibleDirector::AnsibleCollectionRole
      acv = consumable.ansible_collection_version
      ac = acv.versionable
      fqrn = "#{ac.namespace}.#{ac.name}.#{consumable.name}"
    else
      ar = consumable.versionable
      fqrn = "#{ar.namespace}.#{ar.name}"
    end

    host_role_variables = {}
    role_variables.each do |variable|
      value = resolved[variable]
      host_role_variables[variable.key] = value unless value.nil?
    end

    variables[fqrn] = host_role_variables
  end

  variables
end