-
Notifications
You must be signed in to change notification settings - Fork 897
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19140 from Fryguy/refactor_ansible_runner_workflow
Refactor AnsibleRunnerWorkflow to DRY it up
- Loading branch information
Showing
6 changed files
with
122 additions
and
155 deletions.
There are no files selected for viewing
45 changes: 4 additions & 41 deletions
45
app/models/manageiq/providers/ansible_playbook_workflow.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,12 @@ | ||
class ManageIQ::Providers::AnsiblePlaybookWorkflow < ManageIQ::Providers::AnsibleRunnerWorkflow | ||
def self.job_options(env_vars, extra_vars, playbook_options, timeout, poll_interval, hosts, credentials, verbosity, become_enabled) | ||
{ | ||
:become_enabled => become_enabled, | ||
:credentials => credentials, | ||
:env_vars => env_vars, | ||
:extra_vars => extra_vars, | ||
:hosts => hosts, | ||
:playbook_path => playbook_options[:playbook_path], | ||
:timeout => timeout, | ||
:poll_interval => poll_interval, | ||
:verbosity => verbosity | ||
} | ||
def execution_type | ||
"playbook" | ||
end | ||
|
||
def pre_playbook | ||
# A step before running the playbook for any optional setup tasks | ||
queue_signal(:run_playbook) | ||
end | ||
|
||
def run_playbook | ||
def launch_runner | ||
env_vars, extra_vars, playbook_path = options.values_at(:env_vars, :extra_vars, :playbook_path) | ||
kwargs = options.slice(:credentials, :hosts, :verbosity, :become_enabled) | ||
|
||
response = Ansible::Runner.run_async(env_vars, extra_vars, playbook_path, kwargs) | ||
if response.nil? | ||
queue_signal(:abort, "Failed to run ansible playbook", "error") | ||
else | ||
context[:ansible_runner_response] = response.dump | ||
|
||
started_on = Time.now.utc | ||
update_attributes!(:context => context, :started_on => started_on) | ||
miq_task.update_attributes!(:started_on => started_on) | ||
|
||
queue_signal(:poll_runner) | ||
end | ||
Ansible::Runner.run_async(env_vars, extra_vars, playbook_path, kwargs) | ||
end | ||
|
||
def load_transitions | ||
super.tap do |transactions| | ||
transactions.merge!( | ||
:start => {'waiting_to_start' => 'pre_playbook'}, | ||
:run_playbook => {'pre_playbook' => 'running'}, | ||
) | ||
end | ||
end | ||
|
||
alias start pre_playbook | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,12 @@ | ||
class ManageIQ::Providers::AnsibleRoleWorkflow < ManageIQ::Providers::AnsibleRunnerWorkflow | ||
def self.job_options(env_vars, extra_vars, role_options, timeout, poll_interval, hosts, credentials, verbosity, become_enabled) | ||
{ | ||
:become_enabled => become_enabled, | ||
:credentials => credentials, | ||
:env_vars => env_vars, | ||
:extra_vars => extra_vars, | ||
:hosts => hosts, | ||
:role_name => role_options[:role_name], | ||
:roles_path => role_options[:roles_path], | ||
:role_skip_facts => role_options[:role_skip_facts], | ||
:timeout => timeout, | ||
:poll_interval => poll_interval, | ||
:verbosity => verbosity | ||
} | ||
def execution_type | ||
"role" | ||
end | ||
|
||
def pre_role | ||
# A step before running the playbook for any optional setup tasks | ||
queue_signal(:run_role) | ||
end | ||
|
||
def run_role | ||
def launch_runner | ||
env_vars, extra_vars, role_name, roles_path, role_skip_facts = options.values_at(:env_vars, :extra_vars, :role_name, :roles_path, :role_skip_facts) | ||
role_skip_facts = true if role_skip_facts.nil? | ||
response = Ansible::Runner.run_role_async(env_vars, extra_vars, role_name, :roles_path => roles_path, :role_skip_facts => role_skip_facts) | ||
if response.nil? | ||
queue_signal(:abort, "Failed to run ansible role", "error") | ||
else | ||
context[:ansible_runner_response] = response.dump | ||
|
||
started_on = Time.now.utc | ||
update_attributes!(:context => context, :started_on => started_on) | ||
miq_task.update_attributes!(:started_on => started_on) | ||
|
||
queue_signal(:poll_runner) | ||
end | ||
Ansible::Runner.run_role_async(env_vars, extra_vars, role_name, :roles_path => roles_path, :role_skip_facts => role_skip_facts) | ||
end | ||
|
||
def load_transitions | ||
super.tap do |transactions| | ||
transactions.merge!( | ||
:start => {'waiting_to_start' => 'pre_role'}, | ||
:run_role => {'pre_role' => 'running' }, | ||
) | ||
end | ||
end | ||
|
||
alias start pre_role | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.