Class: ForemanAnsibleDirector::Generators::ContentGenerator

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

Class Method Summary collapse

Class Method Details

.generate(host) ⇒ 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/lib/foreman_ansible_director/generators/content_generator.rb', line 7

def generate(host)
  host_content = host.ansible_content_assignments
  content = []

  host_content.each do |content_assignment|
    if content_assignment.consumable.is_a? ::ForemanAnsibleDirector::AnsibleCollectionRole

      collection_role = content_assignment.consumable
      collection_version = collection_role.ansible_collection_version
      collection = collection_version.versionable

      cu = collection
      cuv = collection_version

    else # content_assignment.consumable.is_a? AnsibleRole

      cu = content_assignment.consumable
      cuv = content_assignment.content_unit_version

    end

    content << begin
      if cuv.source_type == 'git'
        distribution_suffix = Base64.encode64(cuv.version[0, 16]).strip
        {
          type: cu.type == 'ForemanAnsibleDirector::AnsibleCollection' ? 'collection' : 'role',
          identifier: cu.full_name,
          version: cuv.version,
          source: "https://#{SETTINGS[:fqdn]}/pulp_ansible/galaxy/#{host.organization_id}/#{cu.full_name}-#{cuv.source_type}-#{distribution_suffix}",
        }
      else
        {
          type: cu.type == 'ForemanAnsibleDirector::AnsibleCollection' ? 'collection' : 'role',
          identifier: cu.full_name,
          version: cuv.version,
          source: "https://#{SETTINGS[:fqdn]}/pulp_ansible/galaxy/#{host.organization_id}/#{cu.full_name}-#{cuv.source_type}",
        }
      end
    end
  end

  content
end