20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'app/models/concerns/foreman_puppet/extensions/provisioning_template.rb', line 20
def templates_by_template_combinations(templates, hosts_or_conditions)
if hosts_or_conditions.is_a?(Hash)
conditions = []
if hosts_or_conditions[:hostgroup_id] && hosts_or_conditions[:environment_id]
conditions << { hostgroup_id: Array.wrap(hosts_or_conditions[:hostgroup_id]), environment_id: Array.wrap(hosts_or_conditions[:environment_id]) }
end
conditions << { hostgroup_id: Array.wrap(hosts_or_conditions[:hostgroup_id]), environment_id: [nil] } if hosts_or_conditions[:hostgroup_id]
conditions << { hostgroup_id: [nil], environment_id: Array.wrap(hosts_or_conditions[:environment_id]) } if hosts_or_conditions[:environment_id]
else
conditions = [{
hostgroup_id: hosts_or_conditions.pluck(:hostgroup_id) | [nil],
environment_id: hosts_or_conditions.joins(:puppet).pluck('host_puppet_facets.environment_id') | [nil],
}]
end
tpls = templates.where('1=0')
conditions.each do |cond|
tpls = templates.joins(:template_combinations).where(template_combinations: cond).distinct
return tpls if tpls.any?
end
tpls
end
|