foreman_ansible 10.2.0 → 11.0.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/concerns/foreman/controller/parameters/job_template_extensions.rb +17 -0
- data/app/controllers/foreman_ansible/api/v2/job_templates_controller_extensions.rb +18 -0
- data/app/helpers/foreman_ansible/ansible_reports_helper.rb +13 -0
- data/app/models/foreman_ansible/ansible_provider.rb +1 -1
- data/app/views/api/v2/job_templates/job_templates.json.rabl +3 -0
- data/app/views/foreman_ansible/config_reports/_ansible.html.erb +6 -2
- data/app/views/job_templates/_job_template_callback_tab_content.html.erb +3 -0
- data/app/views/job_templates/_job_template_callback_tab_headers.html.erb +13 -0
- data/db/migrate/20221003153000_add_ansible_callback_enabled_to_templates.rb +10 -0
- data/lib/foreman_ansible/engine.rb +3 -0
- data/lib/foreman_ansible/register.rb +15 -1
- data/lib/foreman_ansible/version.rb +1 -1
- data/test/unit/ansible_provider_test.rb +3 -4
- data/test/unit/helpers/ansible_reports_helper_test.rb +14 -0
- metadata +17 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 348701b380a514ccae60dda27305a137438dd4cd2812f9515e071a527a0b20c5
|
4
|
+
data.tar.gz: ab770d603437ed890a945381d28411e0caff547f6bef26b22c98191fe6317b98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a780ccd49ae7534e43de5ea1f50aab631b3f59c30c5793455e242568b77d2572fe187f7f0c75667cb1c22ccfd03666dd2ce7df2541cb974df1693ff58079250
|
7
|
+
data.tar.gz: ab9bdea79a470967e8c6592d7166317668a5d9f892887b8d715fc1daaa9a8ce99959cb5c4da2496dabf4b9e4d2ada5909c2e78bfa250bcd13d2250d7d32a1473
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Foreman
|
2
|
+
module Controller
|
3
|
+
module Parameters
|
4
|
+
module JobTemplateExtensions
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
class_methods do
|
8
|
+
def job_template_params_filter
|
9
|
+
super.tap do |filter|
|
10
|
+
filter.permit :ansible_callback_enabled
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ForemanAnsible
|
4
|
+
module Api
|
5
|
+
module V2
|
6
|
+
# Extends the job_templates api controller to support creating/updating with ansible callback plugin
|
7
|
+
module JobTemplatesControllerExtensions
|
8
|
+
extend Apipie::DSL::Concern
|
9
|
+
|
10
|
+
update_api(:create, :update) do
|
11
|
+
param :job_template, Hash do
|
12
|
+
param :ansible_callback_enabled, :bool, :desc => N_('Enable the callback plugin for this template')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -27,6 +27,8 @@ module ForemanAnsible
|
|
27
27
|
|
28
28
|
def ansible_module_message(log)
|
29
29
|
msg_json = parsed_message_json(log)
|
30
|
+
return _("Execution error: #{msg_json['msg']}") if msg_json['failed'].present?
|
31
|
+
|
30
32
|
module_action = msg_json['module']
|
31
33
|
case module_action
|
32
34
|
when 'package'
|
@@ -67,6 +69,17 @@ module ForemanAnsible
|
|
67
69
|
false
|
68
70
|
end
|
69
71
|
|
72
|
+
def show_full_error_message_value(message_value)
|
73
|
+
tag.div class: 'replace-hidden-value' do
|
74
|
+
link_to_function(icon_text('plus', '', class: 'small'), 'replace_value_control(this, "div")',
|
75
|
+
title: _('Show full value'),
|
76
|
+
class: 'replace-hidden-value pull-right') +
|
77
|
+
(tag.span class: 'full-value' do
|
78
|
+
message_value
|
79
|
+
end)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
70
83
|
private
|
71
84
|
|
72
85
|
def parsed_message_json(log)
|
@@ -123,7 +123,7 @@ if defined? ForemanRemoteExecution
|
|
123
123
|
|
124
124
|
def ansible_command?(template)
|
125
125
|
template.remote_execution_features.
|
126
|
-
where(:label => 'ansible_run_host').empty?
|
126
|
+
where(:label => 'ansible_run_host').empty? && !template.ansible_callback_enabled
|
127
127
|
end
|
128
128
|
end
|
129
129
|
end
|
@@ -29,8 +29,12 @@
|
|
29
29
|
<% end %>
|
30
30
|
</ul>
|
31
31
|
<% else %>
|
32
|
-
|
33
|
-
|
32
|
+
<% allowed_length = 150 %>
|
33
|
+
<div class='pull-left'>
|
34
|
+
<%= truncate(log_message, length: allowed_length) %>
|
35
|
+
</div>
|
36
|
+
<%= show_full_error_message_value(log_message) if log_message.length > allowed_length %>
|
37
|
+
<% end %>
|
34
38
|
</td>
|
35
39
|
</tr>
|
36
40
|
<% end %>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<li><a id="ansible_tab_header" href="#ansible_callback_enabled" data-toggle="tab"><%= _("Ansible") %></a></li>
|
2
|
+
<script type="text/javascript">
|
3
|
+
$(document).ready(function () {
|
4
|
+
var provider_type = $('#job_template_provider_type');
|
5
|
+
provider_type.change(setAnsibleTabVisibilityByProvider);
|
6
|
+
provider_type.change();
|
7
|
+
|
8
|
+
function setAnsibleTabVisibilityByProvider() {
|
9
|
+
var tab_header = $("#ansible_tab_header");
|
10
|
+
this.value === 'Ansible' ? tab_header.show() : tab_header.hide();
|
11
|
+
}
|
12
|
+
});
|
13
|
+
</script>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class AddAnsibleCallbackEnabledToTemplates < ActiveRecord::Migration[6.0]
|
4
|
+
def change
|
5
|
+
add_column :templates, :ansible_callback_enabled, :boolean, default: false
|
6
|
+
RemoteExecutionFeature.where(label: 'ansible_run_host').each do |rex_feature|
|
7
|
+
Template.find(rex_feature.job_template_id).update(ansible_callback_enabled: true)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -74,6 +74,9 @@ module ForemanAnsible
|
|
74
74
|
::Api::V2::HostgroupsController.include ForemanAnsible::Api::V2::HostgroupsControllerExtensions
|
75
75
|
::Api::V2::HostgroupsController.include ForemanAnsible::Api::V2::HostgroupsParamGroupExtensions
|
76
76
|
::ConfigReportImporter.include ForemanAnsible::AnsibleReportImporter
|
77
|
+
::Api::V2::JobTemplatesController.include ForemanAnsible::Api::V2::JobTemplatesControllerExtensions
|
78
|
+
::Api::V2::JobTemplatesController.include Foreman::Controller::Parameters::JobTemplateExtensions
|
79
|
+
::JobTemplatesController.include Foreman::Controller::Parameters::JobTemplateExtensions
|
77
80
|
ReportImporter.register_smart_proxy_feature('Ansible')
|
78
81
|
rescue StandardError => e
|
79
82
|
Rails.logger.warn "Foreman Ansible: skipping engine hook (#{e})"
|
@@ -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.6'
|
5
5
|
|
6
6
|
settings do
|
7
7
|
category :ansible, N_('Ansible') do
|
@@ -237,6 +237,8 @@ Foreman::Plugin.register :foreman_ansible do
|
|
237
237
|
register_report_origin 'Ansible', 'ConfigReport'
|
238
238
|
end
|
239
239
|
|
240
|
+
extend_rabl_template 'api/v2/job_templates/show', 'api/v2/job_templates/job_templates'
|
241
|
+
|
240
242
|
describe_host do
|
241
243
|
multiple_actions_provider :ansible_hosts_multiple_actions
|
242
244
|
end
|
@@ -257,4 +259,16 @@ Foreman::Plugin.register :foreman_ansible do
|
|
257
259
|
:partial => 'foreman/smart_proxies/update_smart_proxy',
|
258
260
|
:onlyif => ->(proxy, view) { view.can_update_proxy?(proxy) }
|
259
261
|
end
|
262
|
+
extend_page('templates/_form') do |context|
|
263
|
+
context.add_pagelet :tab_headers,
|
264
|
+
:name => _('Ansible'),
|
265
|
+
:partial => 'job_templates/job_template_callback_tab_headers',
|
266
|
+
:onlyif => ->(subject, _view) { subject.is_a? JobTemplate }
|
267
|
+
end
|
268
|
+
extend_page('templates/_form') do |context|
|
269
|
+
context.add_pagelet :tab_content,
|
270
|
+
:name => _('Ansible'),
|
271
|
+
:partial => 'job_templates/job_template_callback_tab_content',
|
272
|
+
:onlyif => ->(subject, _view) { subject.is_a? JobTemplate }
|
273
|
+
end
|
260
274
|
end
|
@@ -12,16 +12,15 @@ class AnsibleProviderTest < ActiveSupport::TestCase
|
|
12
12
|
assert command_options['ansible_inventory']
|
13
13
|
end
|
14
14
|
|
15
|
-
context 'when
|
15
|
+
context 'when ansible_callback_enabled is set to false' do
|
16
16
|
it 'sets enables :remote_execution_command to true' do
|
17
17
|
assert command_options[:remote_execution_command]
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
context 'when
|
21
|
+
context 'when ansible_callback_enabled is set to true' do
|
22
22
|
it 'has remote_execution_command false' do
|
23
|
-
|
24
|
-
template_invocation.template.remote_execution_features << rex_feature
|
23
|
+
template_invocation.template.ansible_callback_enabled = true
|
25
24
|
assert_not command_options[:remote_execution_command]
|
26
25
|
end
|
27
26
|
end
|
@@ -19,4 +19,18 @@ ANSIBLELOG
|
|
19
19
|
ansible_module_message(log).to_s
|
20
20
|
)
|
21
21
|
end
|
22
|
+
|
23
|
+
test 'module message extraction with error' do
|
24
|
+
log_value = <<-ANSIBLELOG.strip_heredoc
|
25
|
+
{"msg": "AnsibleUndefinedVariable", "changed": false, "_ansible_no_log": false, "failed": true, "module": "template", "exception": "raise AnsibleUndefinedVariable"}
|
26
|
+
ANSIBLELOG
|
27
|
+
message = FactoryBot.build(:message, value: log_value)
|
28
|
+
log = FactoryBot.build(:log, message: message)
|
29
|
+
log.message = message
|
30
|
+
|
31
|
+
assert_match(
|
32
|
+
'Execution error: AnsibleUndefinedVariable',
|
33
|
+
ansible_module_message(log).to_s
|
34
|
+
)
|
35
|
+
end
|
22
36
|
end
|
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: 11.0.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: 2023-01-
|
11
|
+
date: 2023-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: acts_as_list
|
@@ -42,22 +42,16 @@ dependencies:
|
|
42
42
|
name: foreman_remote_execution
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '8.0'
|
48
|
-
- - "<"
|
45
|
+
- - "~>"
|
49
46
|
- !ruby/object:Gem::Version
|
50
|
-
version: '
|
47
|
+
version: '9.0'
|
51
48
|
type: :runtime
|
52
49
|
prerelease: false
|
53
50
|
version_requirements: !ruby/object:Gem::Requirement
|
54
51
|
requirements:
|
55
|
-
- - "
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
version: '8.0'
|
58
|
-
- - "<"
|
52
|
+
- - "~>"
|
59
53
|
- !ruby/object:Gem::Version
|
60
|
-
version: '
|
54
|
+
version: '9.0'
|
61
55
|
- !ruby/object:Gem::Dependency
|
62
56
|
name: foreman-tasks
|
63
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -92,10 +86,12 @@ files:
|
|
92
86
|
- app/controllers/api/v2/ansible_variables_controller.rb
|
93
87
|
- app/controllers/concerns/foreman/controller/parameters/ansible_override_value.rb
|
94
88
|
- app/controllers/concerns/foreman/controller/parameters/ansible_variable.rb
|
89
|
+
- app/controllers/concerns/foreman/controller/parameters/job_template_extensions.rb
|
95
90
|
- app/controllers/foreman_ansible/api/v2/hostgroups_controller_extensions.rb
|
96
91
|
- app/controllers/foreman_ansible/api/v2/hostgroups_param_group_extensions.rb
|
97
92
|
- app/controllers/foreman_ansible/api/v2/hosts_controller_extensions.rb
|
98
93
|
- app/controllers/foreman_ansible/api/v2/hosts_param_group_extensions.rb
|
94
|
+
- app/controllers/foreman_ansible/api/v2/job_templates_controller_extensions.rb
|
99
95
|
- app/controllers/foreman_ansible/concerns/api_common.rb
|
100
96
|
- app/controllers/foreman_ansible/concerns/hostgroups_controller_extensions.rb
|
101
97
|
- app/controllers/foreman_ansible/concerns/hosts_controller_extensions.rb
|
@@ -178,6 +174,7 @@ files:
|
|
178
174
|
- app/views/api/v2/ansible_variables/show.json.rabl
|
179
175
|
- app/views/api/v2/hostgroups/ansible_roles.json.rabl
|
180
176
|
- app/views/api/v2/hosts/ansible_roles.json.rabl
|
177
|
+
- app/views/api/v2/job_templates/job_templates.json.rabl
|
181
178
|
- app/views/foreman/smart_proxies/_update_smart_proxy.html.erb
|
182
179
|
- app/views/foreman_ansible/ansible_roles/_select_tab_content.html.erb
|
183
180
|
- app/views/foreman_ansible/ansible_roles/_select_tab_title.html.erb
|
@@ -204,6 +201,8 @@ files:
|
|
204
201
|
- app/views/foreman_ansible/job_templates/run_playbook-ansible_default.erb
|
205
202
|
- app/views/foreman_ansible/job_templates/service_action_-_ansible_default.erb
|
206
203
|
- app/views/foreman_ansible/job_templates/service_action_-_enable_web_console.erb
|
204
|
+
- app/views/job_templates/_job_template_callback_tab_content.html.erb
|
205
|
+
- app/views/job_templates/_job_template_callback_tab_headers.html.erb
|
207
206
|
- app/views/ui_ansible_roles/index.json.rabl
|
208
207
|
- app/views/ui_ansible_roles/main.json.rabl
|
209
208
|
- app/views/ui_ansible_roles/show.json.rabl
|
@@ -223,6 +222,7 @@ files:
|
|
223
222
|
- db/migrate/20200421201839_update_ansible_inv_template_name.rb
|
224
223
|
- db/migrate/20210120150019_add_position_to_ansible_role.rb
|
225
224
|
- db/migrate/20210818083407_fix_ansible_setting_category_to_dsl.rb
|
225
|
+
- db/migrate/20221003153000_add_ansible_callback_enabled_to_templates.rb
|
226
226
|
- db/migrate/20221031114720_rename_capsule_upgrade_playbook.rb
|
227
227
|
- db/seeds.d/100_common_parameters.rb
|
228
228
|
- db/seeds.d/62_ansible_proxy_feature.rb
|
@@ -467,7 +467,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
467
467
|
- !ruby/object:Gem::Version
|
468
468
|
version: '0'
|
469
469
|
requirements: []
|
470
|
-
rubygems_version: 3.1.
|
470
|
+
rubygems_version: 3.1.4
|
471
471
|
signing_key:
|
472
472
|
specification_version: 4
|
473
473
|
summary: Ansible integration with Foreman (theforeman.org)
|
@@ -477,21 +477,21 @@ test_files:
|
|
477
477
|
- test/factories/ansible_variables.rb
|
478
478
|
- test/factories/host_ansible_enhancements.rb
|
479
479
|
- test/fixtures/insights_playbook.yaml
|
480
|
+
- test/fixtures/playbooks_example_output.json
|
480
481
|
- test/fixtures/report.json
|
481
482
|
- test/fixtures/sample_facts.json
|
482
|
-
- test/fixtures/playbooks_example_output.json
|
483
483
|
- test/fixtures/sample_playbooks.json
|
484
484
|
- test/foreman_ansible/helpers/ansible_roles_helper_test.rb
|
485
485
|
- test/functional/ansible_roles_controller_test.rb
|
486
486
|
- test/functional/ansible_variables_controller_test.rb
|
487
487
|
- test/functional/api/v2/ansible_inventories_controller_test.rb
|
488
|
+
- test/functional/api/v2/ansible_playbooks_controller_test.rb
|
488
489
|
- test/functional/api/v2/ansible_roles_controller_test.rb
|
489
490
|
- test/functional/api/v2/ansible_variables_controller_test.rb
|
490
491
|
- test/functional/api/v2/hostgroups_controller_test.rb
|
491
492
|
- test/functional/api/v2/hosts_controller_test.rb
|
492
|
-
- test/functional/api/v2/ansible_playbooks_controller_test.rb
|
493
|
-
- test/functional/ui_ansible_roles_controller_test.rb
|
494
493
|
- test/functional/hosts_controller_test.rb
|
494
|
+
- test/functional/ui_ansible_roles_controller_test.rb
|
495
495
|
- test/graphql/mutations/hosts/assign_ansible_roles_mutation_test.rb
|
496
496
|
- test/graphql/queries/ansible_roles_query_test.rb
|
497
497
|
- test/graphql/queries/host_ansible_roles_query_test.rb
|
@@ -505,6 +505,7 @@ test_files:
|
|
505
505
|
- test/unit/host_ansible_role_test.rb
|
506
506
|
- test/unit/hostgroup_ansible_role_test.rb
|
507
507
|
- test/unit/ignore_roles_test.rb
|
508
|
+
- test/unit/import_playbooks_test.rb
|
508
509
|
- test/unit/import_roles_and_variables.rb
|
509
510
|
- test/unit/lib/proxy_api/ansible_test.rb
|
510
511
|
- test/unit/services/ansible_report_importer_test.rb
|
@@ -515,6 +516,5 @@ test_files:
|
|
515
516
|
- test/unit/services/override_resolver_test.rb
|
516
517
|
- test/unit/services/roles_importer_test.rb
|
517
518
|
- test/unit/services/ui_roles_importer_test.rb
|
518
|
-
- test/unit/import_playbooks_test.rb
|
519
519
|
- test/unit/ansible_provider_test.rb
|
520
520
|
- test/integration/hostgroup_js_test.rb
|