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..d725a95f2 100644 --- a/app/models/foreman_ansible/ansible_provider.rb +++ b/app/models/foreman_ansible/ansible_provider.rb @@ -32,7 +32,7 @@ def proxy_command_options(template_invocation, host) template_invocation.template ), :name => host.name, - :check_mode => host.host_param('ansible_roles_check_mode'), + :check_mode => check_mode?(template_invocation.template, host), :cleanup_working_dirs => cleanup_working_dirs?(host) ) end @@ -125,6 +125,10 @@ def ansible_command?(template) template.remote_execution_features. where(:label => 'ansible_run_host').empty? && !template.ansible_callback_enabled end + + def check_mode?(template, host) + host.host_param('ansible_roles_check_mode') || template.ansible_check_mode + end end end 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