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/playbook_generator.rb', line 7
def generate(resolved_host_content:)
tasks = []
resolved_host_content.each do |content_assignment|
consumable = content_assignment[:cuv]
next unless consumable
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
load_vars_block = {
name: "Load variables for #{fqrn}",
"ansible.builtin.include_vars": {
file: "#{fqrn}_vars.yaml",
},
}
load_role_block = {
name: "Run role #{fqrn}",
"ansible.builtin.include_role": {
name: fqrn,
},
}
tasks << load_vars_block
tasks << load_role_block
end
[{
name: 'Playbook',
hosts: 'all',
gather_facts: true,
tasks: tasks,
}]
end
|