foreman_ansible 10.4.1 → 10.4.3

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: 6036f9a1d90705a4459c56093084b63c953a7c657a125f4f04ca878fb9bc7552
4
- data.tar.gz: 5354e5227c4eccf6fcee0f721b3e03a10d0d119354d3dc3b2aa742ad44105023
3
+ metadata.gz: 43677522138ced457422019bc60d466cc4ff22956ce56cf35c6fad5bc6227aae
4
+ data.tar.gz: a1523c4616c40ee68cd0209668d34f6a8ae20a817742181ca71f54580b38706f
5
5
  SHA512:
6
- metadata.gz: a29b28a5c665e8af6f52b9b5b2e7ff94f88f87912795ef54c5eedbb7347c666796a42c09456bcd6b50ed30e1d17a1e28f25ab23929fad6b34a4b51ceb87f5131
7
- data.tar.gz: 482d9f6ee4f9c1367a45d87cd4158c29ef88ca2860b6183cdf159123a5a9cf88c7bcca18549b7d448cfff9a5094a3eda24f782f7cd1339e0d0d1fd9abfb1b28c
6
+ metadata.gz: a513cd384608bf244807afc825d8f0db7e1984fbd1acc836cff5d4a35fbbcdb2163d56dea7927f5ff76c3b49dc3c2d9a84c21a0e0946f821058944054b15ba9a
7
+ data.tar.gz: 271871a432184fc08437e02cac8fc5a7389f9cb1a475727d96aa2870fe8beb9b11e35b926771946d48df9e13de34e01130b4294f9b1a54bf6a7644a5fe43559d
@@ -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
@@ -4,18 +4,38 @@ module ForemanAnsible
4
4
  module AnsibleHostgroupsHelper
5
5
  def ansible_hostgroups_actions(hostgroup)
6
6
  actions = []
7
- play_roles = if hostgroup.all_ansible_roles.empty?
8
- { action: { content: (link_to _('Run all Ansible roles'), 'javascript:void(0);', disabled: true, title: 'No roles assigned', class: 'disabled'), options: { class: 'disabled' } }, priority: 31 }
9
- else
10
- { action: display_link_if_authorized(_('Run all Ansible roles'), hash_for_play_roles_hostgroup_path(id: hostgroup), 'data-no-turbolink': true, title: _('Run all Ansible roles on hosts belonging to this host group')), priority: 31 }
11
- end
7
+ is_hostgroup_empty = hostgroup.all_ansible_roles.empty? || hostgroup.hosts_count.zero?
12
8
 
13
- assign_jobs = { action: { content: (link_to _('Configure Ansible Job'), "/ansible/hostgroups/#{hostgroup.id}", class: 'la') }, priority: 32 }
9
+ if User.current.can?(:create_job_invocations)
10
+ actions << {
11
+ action: if is_hostgroup_empty
12
+ disabled_action_link(_('Run all Ansible roles'))
13
+ else
14
+ display_link_if_authorized(_('Run all Ansible roles'), hash_for_play_roles_hostgroup_path(id: hostgroup), 'data-no-turbolink': true, title: _('Run all Ansible roles on hosts belonging to this host group'))
15
+ end,
16
+ priority: 31
17
+ }
18
+ end
14
19
 
15
- actions.push play_roles if User.current.can?(:create_job_invocations)
16
- actions.push assign_jobs if User.current.can?(:view_job_invocations) && User.current.can?(:view_recurring_logics)
20
+ if User.current.can?(:view_job_invocations) && User.current.can?(:view_recurring_logics)
21
+ actions << {
22
+ action: if is_hostgroup_empty
23
+ disabled_action_link(_('Configure Ansible Job'))
24
+ else
25
+ link_to(_('Configure Ansible Job'), "/ansible/hostgroups/#{hostgroup.id}", class: 'la')
26
+ end,
27
+ priority: 32
28
+ }
29
+ end
17
30
 
18
31
  actions
19
32
  end
33
+
34
+ def disabled_action_link(text)
35
+ {
36
+ content: link_to(text, 'javascript:void(0);', disabled: true, title: _('No roles/hosts assigned'), class: 'disabled'),
37
+ options: { class: 'disabled' }
38
+ }
39
+ end
20
40
  end
21
41
  end
@@ -27,7 +27,13 @@ module ForemanAnsible
27
27
  end
28
28
 
29
29
  def proxy_update_button(proxy)
30
- feature = RemoteExecutionFeature.feature(:ansible_run_capsule_upgrade)
30
+ name = if Foreman::Plugin.find('foreman_theme_satellite').present?
31
+ :ansible_run_capsule_upgrade
32
+ else
33
+ :ansible_run_smart_proxy_upgrade
34
+ end
35
+
36
+ feature = RemoteExecutionFeature.feature(name)
31
37
  return if feature.nil?
32
38
 
33
39
  path = new_job_invocation_path(:host_ids => proxy.infrastructure_host_facets.pluck(:host_id),
@@ -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
@@ -1,5 +1,5 @@
1
1
  <%#
2
- name: Smart Proxy Upgrade Playbook
2
+ name: Capsule Upgrade Playbook
3
3
  snippet: false
4
4
  template_inputs:
5
5
  - name: target_version
@@ -26,8 +26,8 @@ feature: ansible_run_capsule_upgrade
26
26
  - hosts: all
27
27
  vars:
28
28
  target_version: "<%= input('target_version').present? ? input('target_version') : product_short_version %>"
29
- <% if plugin_present?('foreman_theme_satellite') -%>
30
29
  tasks:
30
+ <% if plugin_present?('foreman_theme_satellite') -%>
31
31
  - name: Gather the rpm package facts
32
32
  package_facts:
33
33
  manager: auto
@@ -75,35 +75,7 @@ feature: ansible_run_capsule_upgrade
75
75
  fail:
76
76
  msg: "Failed! Capsule server upgrade failed. See /var/log/foreman-installer/capsule.log in the Capsule server for more information"
77
77
  <% else -%>
78
- tasks:
79
- - name: Gather the rpm package facts
80
- package_facts:
81
- manager: auto
82
-
83
- - name: Fail if the target server is a Foreman server
78
+ - name: Fail if foreman_theme_satellite is missing
84
79
  fail:
85
- msg: "This playbook cannot be executed on a Foreman server. Use only on a Smart Proxy server."
86
- when: "'foreman' in ansible_facts.packages"
87
-
88
- - name: Install foreman release gpg key
89
- rpm_key:
90
- state: present
91
- key: http://yum.theforeman.org/releases/{{ target_version }}/RPM-GPG-KEY-foreman
92
- when: target_version != "nightly"
93
-
94
- - name: Update foreman repositories
95
- package:
96
- name: https://yum.theforeman.org/releases/{{ target_version }}/el{{ ansible_distribution_major_version }}/{{ ansible_architecture }}/foreman-release.rpm
97
- state: installed
98
-
99
- - name: Clean yum metadata
100
- command: yum clean all
101
-
102
- - name: Update all packages
103
- package:
104
- name: '*'
105
- state: latest
106
-
107
- - name: Run the installer
108
- shell: foreman-installer
80
+ msg: "Failed! The plugin foreman_theme_satellite is not present. This playbook is only for use with Satellite."
109
81
  <% end -%>
@@ -0,0 +1,59 @@
1
+ <%#
2
+ name: Smart Proxy Upgrade Playbook
3
+ snippet: false
4
+ template_inputs:
5
+ - name: target_version
6
+ required: false
7
+ input_type: user
8
+ advanced: false
9
+ value_type: plain
10
+ hidden_value: false
11
+ - name: whitelist_options
12
+ required: false
13
+ input_type: user
14
+ advanced: false
15
+ value_type: plain
16
+ hidden_value: false
17
+ model: JobTemplate
18
+ job_category: Maintenance Operations
19
+ description_format: "%{template_name}"
20
+ provider_type: Ansible
21
+ kind: job_template
22
+ feature: ansible_run_smart_proxy_upgrade
23
+ %>
24
+
25
+ ---
26
+ - hosts: all
27
+ vars:
28
+ target_version: "<%= input('target_version').present? ? input('target_version') : product_short_version %>"
29
+ tasks:
30
+ - name: Gather the rpm package facts
31
+ package_facts:
32
+ manager: auto
33
+
34
+ - name: Fail if the target server is a Foreman server
35
+ fail:
36
+ msg: "This playbook cannot be executed on a Foreman server. Use only on a Smart Proxy server."
37
+ when: "'foreman' in ansible_facts.packages"
38
+
39
+ - name: Install foreman release gpg key
40
+ rpm_key:
41
+ state: present
42
+ key: http://yum.theforeman.org/releases/{{ target_version }}/RPM-GPG-KEY-foreman
43
+ when: target_version != "nightly"
44
+
45
+ - name: Update foreman repositories
46
+ package:
47
+ name: https://yum.theforeman.org/releases/{{ target_version }}/el{{ ansible_distribution_major_version }}/{{ ansible_architecture }}/foreman-release.rpm
48
+ state: installed
49
+
50
+ - name: Clean yum metadata
51
+ command: yum clean all
52
+
53
+ - name: Update all packages
54
+ package:
55
+ name: '*'
56
+ state: latest
57
+
58
+ - name: Run the installer
59
+ shell: foreman-installer
@@ -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.where(id: rex_feature.job_template_id).update_all(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})"
@@ -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.1'
7
+ VERSION = '10.4.3'
8
8
  end
@@ -10,21 +10,23 @@ class HostgroupJsTest < IntegrationTestWithJavascript
10
10
  FactoryBot.create(:host, :hostgroup_id => hostgroup_with_roles.id)
11
11
  end
12
12
 
13
- test 'hostgroup without roles should have disabled link' do
13
+ test 'hostgroup without roles should have disabled links' do
14
14
  visit hostgroups_path(search: hostgroup.name)
15
15
 
16
16
  first_row = page.find('table > tbody > tr:nth-child(1)')
17
17
  first_row.find('td:nth-child(4) > div > a').click
18
18
 
19
19
  assert_includes first(:link, 'Run all Ansible roles')[:class], 'disabled'
20
+ assert_includes first(:link, 'Configure Ansible Job')[:class], 'disabled'
20
21
  end
21
22
 
22
- test 'hostgroup with roles should have clickable link' do
23
+ test 'hostgroup with roles should have clickable links' do
23
24
  visit hostgroups_path(search: hostgroup_with_roles.name)
24
25
 
25
26
  first_row = page.find('table > tbody > tr:nth-child(1)')
26
27
  first_row.find('td:nth-child(4) > div > a').click
27
28
 
28
29
  assert_not first(:link, 'Run all Ansible roles')[:class].include?('disabled')
30
+ assert_not first(:link, 'Configure Ansible Job')[:class].include?('disabled')
29
31
  end
30
32
  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
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.1
4
+ version: 10.4.3
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-27 00:00:00.000000000 Z
11
+ date: 2023-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: acts_as_list
@@ -86,10 +86,12 @@ files:
86
86
  - app/controllers/api/v2/ansible_variables_controller.rb
87
87
  - app/controllers/concerns/foreman/controller/parameters/ansible_override_value.rb
88
88
  - app/controllers/concerns/foreman/controller/parameters/ansible_variable.rb
89
+ - app/controllers/concerns/foreman/controller/parameters/job_template_extensions.rb
89
90
  - app/controllers/foreman_ansible/api/v2/hostgroups_controller_extensions.rb
90
91
  - app/controllers/foreman_ansible/api/v2/hostgroups_param_group_extensions.rb
91
92
  - app/controllers/foreman_ansible/api/v2/hosts_controller_extensions.rb
92
93
  - app/controllers/foreman_ansible/api/v2/hosts_param_group_extensions.rb
94
+ - app/controllers/foreman_ansible/api/v2/job_templates_controller_extensions.rb
93
95
  - app/controllers/foreman_ansible/concerns/api_common.rb
94
96
  - app/controllers/foreman_ansible/concerns/hostgroups_controller_extensions.rb
95
97
  - app/controllers/foreman_ansible/concerns/hosts_controller_extensions.rb
@@ -172,6 +174,7 @@ files:
172
174
  - app/views/api/v2/ansible_variables/show.json.rabl
173
175
  - app/views/api/v2/hostgroups/ansible_roles.json.rabl
174
176
  - app/views/api/v2/hosts/ansible_roles.json.rabl
177
+ - app/views/api/v2/job_templates/job_templates.json.rabl
175
178
  - app/views/foreman/smart_proxies/_update_smart_proxy.html.erb
176
179
  - app/views/foreman_ansible/ansible_roles/_select_tab_content.html.erb
177
180
  - app/views/foreman_ansible/ansible_roles/_select_tab_title.html.erb
@@ -198,6 +201,9 @@ files:
198
201
  - app/views/foreman_ansible/job_templates/run_playbook-ansible_default.erb
199
202
  - app/views/foreman_ansible/job_templates/service_action_-_ansible_default.erb
200
203
  - app/views/foreman_ansible/job_templates/service_action_-_enable_web_console.erb
204
+ - app/views/foreman_ansible/job_templates/smart_proxy_upgrade_-_ansible_default.erb
205
+ - app/views/job_templates/_job_template_callback_tab_content.html.erb
206
+ - app/views/job_templates/_job_template_callback_tab_headers.html.erb
201
207
  - app/views/ui_ansible_roles/index.json.rabl
202
208
  - app/views/ui_ansible_roles/main.json.rabl
203
209
  - app/views/ui_ansible_roles/show.json.rabl
@@ -217,6 +223,7 @@ files:
217
223
  - db/migrate/20200421201839_update_ansible_inv_template_name.rb
218
224
  - db/migrate/20210120150019_add_position_to_ansible_role.rb
219
225
  - db/migrate/20210818083407_fix_ansible_setting_category_to_dsl.rb
226
+ - db/migrate/20221003153000_add_ansible_callback_enabled_to_templates.rb
220
227
  - db/migrate/20221031114720_rename_capsule_upgrade_playbook.rb
221
228
  - db/seeds.d/100_common_parameters.rb
222
229
  - db/seeds.d/62_ansible_proxy_feature.rb
@@ -492,9 +499,9 @@ test_files:
492
499
  - test/test_plugin_helper.rb
493
500
  - test/unit/ansible_role_test.rb
494
501
  - test/unit/ansible_variable_test.rb
495
- - test/unit/concerns/config_reports_extensions_test.rb
496
502
  - test/unit/concerns/host_managed_extensions_test.rb
497
503
  - test/unit/concerns/hostgroup_extensions_test.rb
504
+ - test/unit/concerns/config_reports_extensions_test.rb
498
505
  - test/unit/helpers/ansible_reports_helper_test.rb
499
506
  - test/unit/host_ansible_role_test.rb
500
507
  - test/unit/hostgroup_ansible_role_test.rb