foreman_ansible 10.4.0 → 11.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c30c3eac6e4a49a8d43c6a654d84b672ef9fa58bbacb8fe2044cc74f33b5a28
4
- data.tar.gz: 8084c75afc69d788093952a8988e3ff883f3726779a94f1de5016c1b857d7435
3
+ metadata.gz: c401e27d48eec2462af90e4ee0f94668b3615ef5e4ce7df7e95e1f5732364447
4
+ data.tar.gz: 1644ac60d2f1b352f46ef5409960d00b64c17f2090eb235b528d88579b9fbbc6
5
5
  SHA512:
6
- metadata.gz: e541db04ed8d5bb3ed65b8239a06366efbda044d57263e4e507534c61a89d566e1270b67593a5c33d423abf13bc7896f76208aa81efc36f58382bd972d40cd7f
7
- data.tar.gz: 5df022f589352f580358303a3172f8062e476884607e1dafd21ee8f140646e106a93419c018b896df55b4bc4cac102374bb92bd3c46e8dc9e42998c52c2bb26e
6
+ metadata.gz: 41fc9d4cf864862b5fa562f5a507407d800962fec4f7a27535dd47850a034ee291b12757a4500ebff1c1649b3c2f83be169f1d537871e00a1472064da5907683
7
+ data.tar.gz: 858837e2b4314f437b4fd361a66c657cc11ee52d4af798e1a7ac17b32443f18ce36dcd78db4004a9fc8ee1d951f56ff3e144d3fe097b699e6f673c6798bb94c3
@@ -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
@@ -79,6 +79,17 @@ module ForemanAnsible
79
79
  false
80
80
  end
81
81
 
82
+ def show_full_error_message_value(message_value)
83
+ tag.div class: 'replace-hidden-value' do
84
+ link_to_function(icon_text('plus', '', class: 'small'), 'replace_value_control(this, "div")',
85
+ title: _('Show full value'),
86
+ class: 'replace-hidden-value pull-right') +
87
+ (tag.span class: 'full-value' do
88
+ message_value
89
+ end)
90
+ end
91
+ end
92
+
82
93
  private
83
94
 
84
95
  def get_results(msg_json)
@@ -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
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ attributes :ansible_callback_enabled
@@ -29,8 +29,12 @@
29
29
  <% end %>
30
30
  </ul>
31
31
  <% else %>
32
- <%= log_message %>
33
- <% end %>
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,3 @@
1
+ <div class="tab-pane" id="ansible_callback_enabled">
2
+ <%= checkbox_f f, :ansible_callback_enabled, :label => _('Enable Ansible Callback'), :disabled => @template.locked? %>
3
+ </div>
@@ -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.5'
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
@@ -4,5 +4,5 @@
4
4
  # This way other parts of Foreman can just call ForemanAnsible::VERSION
5
5
  # and detect what version the plugin is running.
6
6
  module ForemanAnsible
7
- VERSION = '10.4.0'
7
+ VERSION = '11.1.0'
8
8
  end
@@ -12,16 +12,15 @@ class AnsibleProviderTest < ActiveSupport::TestCase
12
12
  assert command_options['ansible_inventory']
13
13
  end
14
14
 
15
- context 'when it is not using the ansible_run_host feature' do
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 it is using the ansible_run_host feature' do
21
+ context 'when ansible_callback_enabled is set to true' do
22
22
  it 'has remote_execution_command false' do
23
- rex_feature = RemoteExecutionFeature.where(:label => 'ansible_run_host', :name => 'Run Ansible roles').first_or_create
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
@@ -20,25 +20,18 @@ ANSIBLELOG
20
20
  )
21
21
  end
22
22
 
23
- test 'module message extraction with action' do
24
- example_report = JSON.parse(File.read(ansible_fixture_file('report.json'))).second
25
- report = ConfigReport.import(example_report)
26
- expected_outputs = [
27
- 'No additional data',
28
- ['Cron job: 0 5,2 * * * date > /dev/null (disabled: false)', 'Cron job: 0 5,2 * * * df > /dev/null (disabled: false)'],
29
- ['Cron job: 0 5,2 * * * hostname > /dev/null (disabled: false)'],
30
- ['Rendered template test1.txt.j2 to /tmp/test1.txt', 'Rendered template test2.txt.j2 to /tmp/test2.txt'],
31
- ['Rendered template test3.txt.j2 to /tmp/test3.txt'],
32
- ['Copy test4.txt to /tmp/test4.txt', 'Copy test5.txt to /tmp/test5.txt'],
33
- ['Copy test6.txt to /tmp/test6.txt'],
34
- ['Service chronyd started (enabled: )', 'Service firewalld started (enabled: )'],
35
- ['Service chronyd started (enabled: )']
36
- ]
37
- actual_outputs = []
38
- report.logs.each do |log|
39
- actual_outputs << ansible_module_message(log)
40
- end
41
- assert_equal expected_outputs, actual_outputs
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
+ )
42
35
  end
43
36
 
44
37
  test 'accepting an almost empty message' do
@@ -79,4 +72,25 @@ ANSIBLELOG
79
72
  ansible_module_message(log).to_s
80
73
  )
81
74
  end
75
+
76
+ test 'module message extraction with action' do
77
+ example_report = JSON.parse(File.read(ansible_fixture_file('report.json'))).second
78
+ report = ConfigReport.import(example_report)
79
+ expected_outputs = [
80
+ 'No additional data',
81
+ ['Cron job: 0 5,2 * * * date > /dev/null (disabled: false)', 'Cron job: 0 5,2 * * * df > /dev/null (disabled: false)'],
82
+ ['Cron job: 0 5,2 * * * hostname > /dev/null (disabled: false)'],
83
+ ['Rendered template test1.txt.j2 to /tmp/test1.txt', 'Rendered template test2.txt.j2 to /tmp/test2.txt'],
84
+ ['Rendered template test3.txt.j2 to /tmp/test3.txt'],
85
+ ['Copy test4.txt to /tmp/test4.txt', 'Copy test5.txt to /tmp/test5.txt'],
86
+ ['Copy test6.txt to /tmp/test6.txt'],
87
+ ['Service chronyd started (enabled: )', 'Service firewalld started (enabled: )'],
88
+ ['Service chronyd started (enabled: )']
89
+ ]
90
+ actual_outputs = []
91
+ report.logs.each do |log|
92
+ actual_outputs << ansible_module_message(log)
93
+ end
94
+ assert_equal expected_outputs, actual_outputs
95
+ end
82
96
  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: 10.4.0
4
+ version: 11.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: 2023-02-12 00:00:00.000000000 Z
11
+ date: 2023-02-14 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: '10'
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: '10'
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