Skip to content

Commit

Permalink
Fixes #37942 - Adding Ansible Check Mode to Ansible Job Templates
Browse files Browse the repository at this point in the history
  • Loading branch information
bnerickson committed Oct 23, 2024
1 parent 0bd8029 commit 9e70d02
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion app/models/foreman_ansible/ansible_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/api/v2/job_templates/job_templates.json.rabl
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# frozen_string_literal: true

attributes :ansible_callback_enabled
attributes :ansible_callback_enabled, :ansible_check_mode
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<div class="tab-pane" id="ansible_callback_enabled">
<%= 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? %>
</div>
10 changes: 10 additions & 0 deletions db/migrate/20241022000000_add_ansible_check_mode_to_templates.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9e70d02

Please sign in to comment.