From 614c4f20cf7cbf9b8cf2b01bd558f4c842261426 Mon Sep 17 00:00:00 2001 From: Ben Erickson Date: Tue, 22 Oct 2024 13:37:07 -0700 Subject: [PATCH] Fixes #37942 - Adding Ansible Check Mode to Ansible Job Templates --- .../controller/parameters/job_template_extensions.rb | 2 +- .../api/v2/job_templates_controller_extensions.rb | 1 + app/models/foreman_ansible/ansible_provider.rb | 1 + app/views/api/v2/job_templates/job_templates.json.rabl | 2 +- .../_job_template_callback_tab_content.html.erb | 1 + ...241022000000_add_ansible_check_mode_to_templates.rb | 10 ++++++++++ 6 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20241022000000_add_ansible_check_mode_to_templates.rb diff --git a/app/controllers/concerns/foreman/controller/parameters/job_template_extensions.rb b/app/controllers/concerns/foreman/controller/parameters/job_template_extensions.rb index 5bed2bff0..36f546614 100644 --- a/app/controllers/concerns/foreman/controller/parameters/job_template_extensions.rb +++ b/app/controllers/concerns/foreman/controller/parameters/job_template_extensions.rb @@ -7,7 +7,7 @@ module JobTemplateExtensions class_methods do def job_template_params_filter super.tap do |filter| - filter.permit :ansible_callback_enabled + filter.permit :ansible_callback_enabled, :ansible_check_mode end end end diff --git a/app/controllers/foreman_ansible/api/v2/job_templates_controller_extensions.rb b/app/controllers/foreman_ansible/api/v2/job_templates_controller_extensions.rb index 3930d5a3c..f973e5803 100644 --- a/app/controllers/foreman_ansible/api/v2/job_templates_controller_extensions.rb +++ b/app/controllers/foreman_ansible/api/v2/job_templates_controller_extensions.rb @@ -10,6 +10,7 @@ module JobTemplatesControllerExtensions update_api(:create, :update) do param :job_template, Hash do param :ansible_callback_enabled, :bool, :desc => N_('Enable the callback plugin for this template') + param :ansible_check_mode, :bool, :desc => N_('Enable Ansible Check Mode for this template') end end end diff --git a/app/models/foreman_ansible/ansible_provider.rb b/app/models/foreman_ansible/ansible_provider.rb index d151fa006..2c37a658c 100644 --- a/app/models/foreman_ansible/ansible_provider.rb +++ b/app/models/foreman_ansible/ansible_provider.rb @@ -33,6 +33,7 @@ def proxy_command_options(template_invocation, host) ), :name => host.name, :check_mode => host.host_param('ansible_roles_check_mode'), + :job_check_mode => template_invocation.template.ansible_check_mode, :cleanup_working_dirs => cleanup_working_dirs?(host) ) end diff --git a/app/views/api/v2/job_templates/job_templates.json.rabl b/app/views/api/v2/job_templates/job_templates.json.rabl index e3c5262fd..6037682ec 100644 --- a/app/views/api/v2/job_templates/job_templates.json.rabl +++ b/app/views/api/v2/job_templates/job_templates.json.rabl @@ -1,3 +1,3 @@ # frozen_string_literal: true -attributes :ansible_callback_enabled +attributes :ansible_callback_enabled, :ansible_check_mode diff --git a/app/views/job_templates/_job_template_callback_tab_content.html.erb b/app/views/job_templates/_job_template_callback_tab_content.html.erb index a3d7011b3..d180dbd2b 100644 --- a/app/views/job_templates/_job_template_callback_tab_content.html.erb +++ b/app/views/job_templates/_job_template_callback_tab_content.html.erb @@ -1,3 +1,4 @@
<%= checkbox_f f, :ansible_callback_enabled, :label => _('Enable Ansible Callback'), :disabled => @template.locked? %> + <%= checkbox_f f, :ansible_check_mode, :label => _('Enable Ansible Check Mode'), :disabled => @template.locked? %>
diff --git a/db/migrate/20241022000000_add_ansible_check_mode_to_templates.rb b/db/migrate/20241022000000_add_ansible_check_mode_to_templates.rb new file mode 100644 index 000000000..fbc60b112 --- /dev/null +++ b/db/migrate/20241022000000_add_ansible_check_mode_to_templates.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class AddAnsibleCheckModeToTemplates < ActiveRecord::Migration[6.0] + def change + add_column :templates, :ansible_check_mode, :boolean, default: false + RemoteExecutionFeature.where(label: 'ansible_run_host').each do |rex_feature| + Template.where(id: rex_feature.job_template_id).update_all(ansible_check_mode: false) + end + end +end