Module: ForemanAnsible::RendererMethods

Extended by:
ActiveSupport::Concern
Defined in:
app/services/foreman_ansible/renderer_methods.rb

Overview

Macro to fetch RH Insights plan playbook

Instance Method Summary collapse

Instance Method Details

#insights_remediation(plan_id, organization_id = Organization.current.id) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/services/foreman_ansible/renderer_methods.rb', line 8

def insights_remediation(plan_id, organization_id = Organization.current.id)
  return "$INSIGHTS_REMEDIATION[#{plan_id}, #{organization_id}]" if preview?

  cached("insights_#{plan_id}_#{organization_id}") do
    Rails.logger.debug 'cache miss for insights plan fetching'
    insights_plan = ForemanAnsible::InsightsPlanRunner.new(
      Organization.find(organization_id),
      plan_id
    )
    rules = insights_plan.playbook
    disclaimer = insights_plan.parse_disclaimer
    hostname_rules_relation = insights_plan.hostname_rules(rules)
    global_rules = insights_plan.rules_to_hash(rules)
    host_playbooks = individual_host_playbooks(hostname_rules_relation,
                                               global_rules)
    "#{disclaimer}\n#{host_playbooks.to_yaml}"
  end
end