foreman_ansible 13.0.6 → 14.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/ui_ansible_roles_controller.rb +2 -2
- data/app/views/ansible_roles/import.html.erb +0 -1
- data/app/views/foreman_ansible/ansible_roles/_select_tab_content.html.erb +0 -1
- data/app/views/foreman_ansible/job_templates/package_action_-_ansible_default.erb +2 -3
- data/db/seeds.d/90_notification_blueprints.rb +0 -13
- data/lib/foreman_ansible/register.rb +1 -3
- data/lib/foreman_ansible/remote_execution.rb +0 -8
- data/lib/foreman_ansible/version.rb +1 -1
- data/webpack/testHelper.js +9 -8
- metadata +2 -8
- data/app/services/foreman_ansible/insights_notification_builder.rb +0 -64
- data/app/services/foreman_ansible/insights_plan_runner.rb +0 -86
- data/app/services/foreman_ansible/renderer_methods.rb +0 -46
- data/app/views/foreman_ansible/job_templates/maintenance_plan.erb +0 -19
- data/test/unit/services/insights_plan_runner_test.rb +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '022826891f9116dddddd19920939b158e53bea4dc5ef646ca21d7004fa359b11'
|
4
|
+
data.tar.gz: 7fcb1aa461c5cdfb79984e4e257e30590418aceff8c8d8b623ad38207e3d3722
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1bd359f9025fd7d9a110decc493c75f03785f2a0ffe08a49ae58cdcf934182e87633d4a6b161383637903054aec59d743f941534731f3afbba9f39adb688def
|
7
|
+
data.tar.gz: 4ed0e468a309542c89867fc626fa88628e43b0a5ece64ee22d9c94cb86ee346ff738dfc768d138b5a8b06c78170d49bd9544742693d35fbd8e0ec916fddf7e30
|
@@ -8,7 +8,7 @@ class UiAnsibleRolesController < ::Api::V2::BaseController
|
|
8
8
|
end
|
9
9
|
|
10
10
|
# restore original method from find_common to ignore resource nesting
|
11
|
-
def resource_scope(
|
12
|
-
@resource_scope ||= scope_for(resource_class,
|
11
|
+
def resource_scope(**kwargs)
|
12
|
+
@resource_scope ||= scope_for(resource_class, **kwargs)
|
13
13
|
end
|
14
14
|
end
|
@@ -30,8 +30,7 @@ template_inputs:
|
|
30
30
|
provider_type: Ansible
|
31
31
|
kind: job_template
|
32
32
|
model: JobTemplate
|
33
|
-
|
34
|
-
|
33
|
+
-%>
|
35
34
|
# For Windows targets use the win_package module instead.
|
36
35
|
---
|
37
36
|
- hosts: all
|
@@ -41,7 +40,7 @@ model: JobTemplate
|
|
41
40
|
<%- end -%>
|
42
41
|
tasks:
|
43
42
|
- package:
|
44
|
-
|
43
|
+
<%= indent(8) { to_yaml({"name" => input('name')}).gsub(/---\n/, '') } -%>
|
45
44
|
state: <%= input('state') %>
|
46
45
|
<%- if input('post_script').present? -%>
|
47
46
|
post_tasks:
|
@@ -1,19 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
blueprints = [
|
4
|
-
{
|
5
|
-
:group => N_('Jobs'),
|
6
|
-
:name => 'insights_remediation_successful',
|
7
|
-
:message => N_('Insights remediation on %{hosts_count}' \
|
8
|
-
' host(s) has finished successfully'),
|
9
|
-
:level => 'success',
|
10
|
-
:actions => {
|
11
|
-
:links => [
|
12
|
-
:path_method => :job_invocation_path,
|
13
|
-
:title => N_('Job Details')
|
14
|
-
]
|
15
|
-
}
|
16
|
-
},
|
17
4
|
{
|
18
5
|
:group => N_('Roles'),
|
19
6
|
:name => 'Sync_roles_and_variables_successfully',
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
Foreman::Plugin.register :foreman_ansible do
|
4
|
-
requires_foreman '>= 3.
|
4
|
+
requires_foreman '>= 3.10.0'
|
5
5
|
register_gettext
|
6
6
|
|
7
7
|
settings do
|
@@ -178,8 +178,6 @@ Foreman::Plugin.register :foreman_ansible do
|
|
178
178
|
'Permissions required for the user which is used by Ansible Tower Dynamic Inventory Item'
|
179
179
|
|
180
180
|
add_all_permissions_to_default_roles
|
181
|
-
extend_template_helpers ForemanAnsible::RendererMethods
|
182
|
-
allowed_template_helpers :insights_remediation
|
183
181
|
|
184
182
|
base_role_assignment_params = { :ansible_role_ids => [],
|
185
183
|
:ansible_roles => [] }
|
@@ -22,14 +22,6 @@ module ForemanAnsible
|
|
22
22
|
' the roles defined for a host'),
|
23
23
|
:host_action_button => true
|
24
24
|
)
|
25
|
-
RemoteExecutionFeature.register(
|
26
|
-
:ansible_run_insights_plan,
|
27
|
-
N_('Ansible: Run Insights maintenance plan'),
|
28
|
-
:description => N_('Runs a given maintenance plan from Red Hat '\
|
29
|
-
'Access Insights given an ID.'),
|
30
|
-
:provided_inputs => %w[organization_id plan_id],
|
31
|
-
:notification_builder => ForemanAnsible::InsightsNotificationBuilder
|
32
|
-
)
|
33
25
|
RemoteExecutionFeature.register(
|
34
26
|
:ansible_run_playbook,
|
35
27
|
N_('Run playbook'),
|
data/webpack/testHelper.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import React from 'react';
|
1
|
+
import React, { useState } from 'react';
|
2
2
|
import { Provider } from 'react-redux';
|
3
3
|
import thunk from 'redux-thunk';
|
4
4
|
import { applyMiddleware, createStore, compose, combineReducers } from 'redux';
|
@@ -42,20 +42,21 @@ export const withReactRouter = Component => props => {
|
|
42
42
|
};
|
43
43
|
|
44
44
|
export const withMockedProvider = Component => props => {
|
45
|
-
const
|
46
|
-
// eslint-disable-next-line react/prop-types
|
47
|
-
const { mocks, ...rest } = props;
|
48
|
-
|
49
|
-
const ctx = {
|
45
|
+
const [context, setContext] = useState({
|
50
46
|
metadata: {
|
51
47
|
UISettings: {
|
52
48
|
perPage: 20,
|
53
49
|
},
|
54
50
|
},
|
55
|
-
};
|
51
|
+
});
|
52
|
+
const contextData = { context, setContext };
|
53
|
+
const ForemanContext = getForemanContext(contextData);
|
54
|
+
|
55
|
+
// eslint-disable-next-line react/prop-types
|
56
|
+
const { mocks, ...rest } = props;
|
56
57
|
|
57
58
|
return (
|
58
|
-
<ForemanContext.Provider value={
|
59
|
+
<ForemanContext.Provider value={contextData}>
|
59
60
|
<MockedProvider mocks={mocks}>
|
60
61
|
<Component {...rest} />
|
61
62
|
</MockedProvider>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_ansible
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 14.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Lobato Garcia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: acts_as_list
|
@@ -171,14 +171,11 @@ files:
|
|
171
171
|
- app/services/foreman_ansible/import_playbooks_success_notification.rb
|
172
172
|
- app/services/foreman_ansible/import_roles_and_variables_error_notification.rb
|
173
173
|
- app/services/foreman_ansible/import_roles_and_variables_success_notification.rb
|
174
|
-
- app/services/foreman_ansible/insights_notification_builder.rb
|
175
|
-
- app/services/foreman_ansible/insights_plan_runner.rb
|
176
174
|
- app/services/foreman_ansible/inventory_creator.rb
|
177
175
|
- app/services/foreman_ansible/override_resolver.rb
|
178
176
|
- app/services/foreman_ansible/playbook_creator.rb
|
179
177
|
- app/services/foreman_ansible/playbooks_importer.rb
|
180
178
|
- app/services/foreman_ansible/proxy_api.rb
|
181
|
-
- app/services/foreman_ansible/renderer_methods.rb
|
182
179
|
- app/services/foreman_ansible/roles_importer.rb
|
183
180
|
- app/services/foreman_ansible/ui_roles_importer.rb
|
184
181
|
- app/services/foreman_ansible/variables_importer.rb
|
@@ -222,7 +219,6 @@ files:
|
|
222
219
|
- app/views/foreman_ansible/job_templates/ansible_windows_updates.erb
|
223
220
|
- app/views/foreman_ansible/job_templates/capsule_upgrade_-_ansible_default.erb
|
224
221
|
- app/views/foreman_ansible/job_templates/convert_to_rhel.erb
|
225
|
-
- app/views/foreman_ansible/job_templates/maintenance_plan.erb
|
226
222
|
- app/views/foreman_ansible/job_templates/module_action_-_ansible_default.erb
|
227
223
|
- app/views/foreman_ansible/job_templates/package_action_-_ansible_default.erb
|
228
224
|
- app/views/foreman_ansible/job_templates/power_action_-_ansible_default.erb
|
@@ -350,7 +346,6 @@ files:
|
|
350
346
|
- test/unit/services/ansible_report_importer_test.rb
|
351
347
|
- test/unit/services/ansible_variables_importer_test.rb
|
352
348
|
- test/unit/services/api_roles_importer_test.rb
|
353
|
-
- test/unit/services/insights_plan_runner_test.rb
|
354
349
|
- test/unit/services/inventory_creator_test.rb
|
355
350
|
- test/unit/services/override_resolver_test.rb
|
356
351
|
- test/unit/services/roles_importer_test.rb
|
@@ -546,7 +541,6 @@ test_files:
|
|
546
541
|
- test/unit/services/ansible_report_importer_test.rb
|
547
542
|
- test/unit/services/ansible_variables_importer_test.rb
|
548
543
|
- test/unit/services/api_roles_importer_test.rb
|
549
|
-
- test/unit/services/insights_plan_runner_test.rb
|
550
544
|
- test/unit/services/inventory_creator_test.rb
|
551
545
|
- test/unit/services/override_resolver_test.rb
|
552
546
|
- test/unit/services/roles_importer_test.rb
|
@@ -1,64 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ForemanAnsible
|
4
|
-
# A class that builds custom notificaton for REX job if it's insights
|
5
|
-
# remediation feature
|
6
|
-
class InsightsNotificationBuilder < ::UINotifications::RemoteExecutionJobs::BaseJobFinish
|
7
|
-
def deliver!
|
8
|
-
::Notification.create!(
|
9
|
-
:audience => Notification::AUDIENCE_USER,
|
10
|
-
:notification_blueprint => blueprint,
|
11
|
-
:initiator => initiator,
|
12
|
-
:message => message,
|
13
|
-
:subject => subject,
|
14
|
-
:actions => {
|
15
|
-
:links => links
|
16
|
-
}
|
17
|
-
)
|
18
|
-
end
|
19
|
-
|
20
|
-
def blueprint
|
21
|
-
name = 'insights_remediation_successful'
|
22
|
-
@blueprint ||= NotificationBlueprint.unscoped.find_by(:name => name)
|
23
|
-
end
|
24
|
-
|
25
|
-
def hosts_count
|
26
|
-
@hosts_count ||= subject.template_invocations_hosts.size
|
27
|
-
end
|
28
|
-
|
29
|
-
def message
|
30
|
-
UINotifications::StringParser.new(blueprint.message,
|
31
|
-
:hosts_count => hosts_count)
|
32
|
-
end
|
33
|
-
|
34
|
-
def links
|
35
|
-
job_links + insights_links
|
36
|
-
end
|
37
|
-
|
38
|
-
def insights_links
|
39
|
-
pattern_template = subject.pattern_template_invocations.first
|
40
|
-
plan_id = pattern_template.input_values.
|
41
|
-
joins(:template_input).
|
42
|
-
where('template_inputs.name' => 'plan_id').
|
43
|
-
first.try(:value)
|
44
|
-
return [] if plan_id.nil?
|
45
|
-
|
46
|
-
[
|
47
|
-
{
|
48
|
-
:href => "/redhat_access/insights/planner/#{plan_id}",
|
49
|
-
:title => _('Remediation Plan')
|
50
|
-
}
|
51
|
-
]
|
52
|
-
end
|
53
|
-
|
54
|
-
def job_links
|
55
|
-
UINotifications::URLResolver.new(
|
56
|
-
subject,
|
57
|
-
:links => [{
|
58
|
-
:path_method => :job_invocation_path,
|
59
|
-
:title => _('Job Details')
|
60
|
-
}]
|
61
|
-
).actions[:links]
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
@@ -1,86 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
if defined?(RedhatAccess)
|
4
|
-
module ForemanAnsible
|
5
|
-
# Fetch information about a plan from RH Insights and run it
|
6
|
-
class InsightsPlanRunner
|
7
|
-
include RedhatAccess::Telemetry::LookUps
|
8
|
-
|
9
|
-
def initialize(organization, plan_id)
|
10
|
-
@organization = organization
|
11
|
-
@plan_id = plan_id
|
12
|
-
end
|
13
|
-
|
14
|
-
def run_playbook
|
15
|
-
rules = playbook
|
16
|
-
hostname_rules_relation = hostname_rules(rules)
|
17
|
-
hosts = hostname_rules_relation.keys.map do |hostname|
|
18
|
-
Host::Managed.find_by(:name => hostname)
|
19
|
-
end
|
20
|
-
|
21
|
-
composer = JobInvocationComposer.for_feature(
|
22
|
-
:ansible_run_insights_plan,
|
23
|
-
hosts,
|
24
|
-
:organization_id => @organization.id, :plan_id => @plan_id
|
25
|
-
)
|
26
|
-
composer.save
|
27
|
-
composer.trigger
|
28
|
-
end
|
29
|
-
|
30
|
-
# Fetches the playbook from the Red Hat Insights API
|
31
|
-
def playbook
|
32
|
-
resource = RestClient::Resource.new(
|
33
|
-
"#{insights_api_host}/r/insights/"\
|
34
|
-
"v3/maintenance/#{@plan_id}/playbook",
|
35
|
-
get_ssl_options_for_org(@organization, nil).\
|
36
|
-
merge(:proxy => get_portal_http_proxy)
|
37
|
-
)
|
38
|
-
@raw_playbook = resource.get.body
|
39
|
-
YAML.safe_load(@raw_playbook)
|
40
|
-
end
|
41
|
-
|
42
|
-
# To parse the disclaimer we iterate over the first lines of the
|
43
|
-
# playbook (all comments) until we get to a line that looks like
|
44
|
-
# "Generated by Red Hat Insights on..."
|
45
|
-
def parse_disclaimer(playbook = @raw_playbook)
|
46
|
-
return '' if playbook.blank?
|
47
|
-
disclaimer = []
|
48
|
-
playbook.split("\n").each do |line|
|
49
|
-
next if line == '---'
|
50
|
-
break unless line[0] == '#'
|
51
|
-
disclaimer << line
|
52
|
-
break if /Generated by Red Hat Insights on/ =~ line
|
53
|
-
end
|
54
|
-
disclaimer.join("\n")
|
55
|
-
end
|
56
|
-
|
57
|
-
# This method creates a hash like this:
|
58
|
-
# {
|
59
|
-
# hostname1 => [rule1,rule2,rule3],
|
60
|
-
# hostname2 => [rule1,rule3],
|
61
|
-
# }
|
62
|
-
#
|
63
|
-
# Rules are distinguished by name and saved without the 'hosts' field
|
64
|
-
# as it's irrelevant in the Foreman REX context ('hosts: all' is used
|
65
|
-
# so that all=job invocation targets)
|
66
|
-
def rules_to_hash(rules)
|
67
|
-
result = {}
|
68
|
-
rules.map do |rule|
|
69
|
-
rule['hosts'] = 'all'
|
70
|
-
result[rule['name']] = rule
|
71
|
-
end
|
72
|
-
result
|
73
|
-
end
|
74
|
-
|
75
|
-
def hostname_rules(rules)
|
76
|
-
result = Hash.new { |h, k| h[k] = [] }
|
77
|
-
rules.each do |rule|
|
78
|
-
rule['hosts'].split(',').each do |host|
|
79
|
-
result[host] << rule['name']
|
80
|
-
end
|
81
|
-
end
|
82
|
-
result
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ForemanAnsible
|
4
|
-
# Macro to fetch RH Insights plan playbook
|
5
|
-
module RendererMethods
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
extend ApipieDSL::Module
|
8
|
-
|
9
|
-
apipie :class, 'Macros related to Ansible playbooks' do
|
10
|
-
name 'Ansible'
|
11
|
-
sections only: %w[all jobs]
|
12
|
-
end
|
13
|
-
|
14
|
-
apipie :method, 'Returns Insights maintenance plan for host' do
|
15
|
-
required :plan_id, String, desc: 'The playbook for the rule coming from insights'
|
16
|
-
optional :organization_id, Integer, desc: 'The Foreman organization associated with the Insights account', default: 'Current organization ID'
|
17
|
-
returns String, desc: 'Insights maintenance plan for host'
|
18
|
-
end
|
19
|
-
def insights_remediation(plan_id, organization_id = Organization.current.id)
|
20
|
-
return "$INSIGHTS_REMEDIATION[#{plan_id}, #{organization_id}]" if preview?
|
21
|
-
|
22
|
-
cached("insights_#{plan_id}_#{organization_id}") do
|
23
|
-
Rails.logger.debug 'cache miss for insights plan fetching'
|
24
|
-
insights_plan = ForemanAnsible::InsightsPlanRunner.new(
|
25
|
-
Organization.find(organization_id),
|
26
|
-
plan_id
|
27
|
-
)
|
28
|
-
rules = insights_plan.playbook
|
29
|
-
disclaimer = insights_plan.parse_disclaimer
|
30
|
-
hostname_rules_relation = insights_plan.hostname_rules(rules)
|
31
|
-
global_rules = insights_plan.rules_to_hash(rules)
|
32
|
-
host_playbooks = individual_host_playbooks(hostname_rules_relation,
|
33
|
-
global_rules)
|
34
|
-
"#{disclaimer}\n#{host_playbooks.to_yaml}"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def individual_host_playbooks(hostname_rules_relation, global_rules)
|
41
|
-
hostname_rules_relation[@host.name].reduce([]) do |acc, cur|
|
42
|
-
acc << global_rules[cur]
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
<%#
|
2
|
-
kind: job_template
|
3
|
-
name: Ansible - Run insights maintenance plan
|
4
|
-
job_category: Ansible Playbook
|
5
|
-
description_format: 'Insights maintenance plan for host'
|
6
|
-
feature: ansible_run_insights_plan
|
7
|
-
template_inputs:
|
8
|
-
- name: plan_id
|
9
|
-
description: The playbook for the rule coming from insights.
|
10
|
-
input_type: user
|
11
|
-
required: true
|
12
|
-
- name: organization_id
|
13
|
-
description: The Foreman organization associated with the Insights account
|
14
|
-
input_type: user
|
15
|
-
required: true
|
16
|
-
provider_type: Ansible
|
17
|
-
%>
|
18
|
-
|
19
|
-
<%= insights_remediation(input(:plan_id), input(:organization_id)) %>
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_plugin_helper'
|
4
|
-
|
5
|
-
if defined? RedhatAccess
|
6
|
-
module ForemanAnsible
|
7
|
-
# Tests for the RH Insights plan runner. Mostly about checking whether
|
8
|
-
# the playbook can be parsed properly
|
9
|
-
class InsightsPlanRunnerTest < ActiveSupport::TestCase
|
10
|
-
test 'disclaimer is saved as raw_playbook' do
|
11
|
-
disclaimer = <<-DISCLAIMER.strip_heredoc.strip
|
12
|
-
# Red Hat Insights has recommended one or more actions for you, a system administrator, to review and if you
|
13
|
-
# deem appropriate, deploy on your systems running Red Hat software. Based on the analysis, we have automatically
|
14
|
-
# generated an Ansible Playbook for you. Please review and test the recommended actions and the Playbook as
|
15
|
-
# they may contain configuration changes, updates, reboots and/or other changes to your systems. Red Hat is not
|
16
|
-
# responsible for any adverse outcomes related to these recommendations or Playbooks.
|
17
|
-
#
|
18
|
-
# Addresses maintenance plan 38439429 (demo)
|
19
|
-
# https://access.redhat.com/insights/planner/438294928
|
20
|
-
# Generated by Red Hat Insights on Wed, 18 Apr 2018 07:54:18 GMT
|
21
|
-
DISCLAIMER
|
22
|
-
|
23
|
-
playbook = File.read(ansible_fixture_file('insights_playbook.yaml'))
|
24
|
-
planner = ::ForemanAnsible::InsightsPlanRunner.new(
|
25
|
-
FactoryBot.build(:organization), rand
|
26
|
-
)
|
27
|
-
assert_empty planner.parse_disclaimer
|
28
|
-
planner.expects(:insights_api_host).returns('')
|
29
|
-
planner.expects(:get_ssl_options_for_org).returns(nil)
|
30
|
-
RestClient::Resource.any_instance.expects(:get).returns(
|
31
|
-
OpenStruct.new(:body => playbook)
|
32
|
-
)
|
33
|
-
planner.playbook
|
34
|
-
assert_equal disclaimer, planner.parse_disclaimer
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|