-
Notifications
You must be signed in to change notification settings - Fork 898
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for using run_role_async
Add the option to use the run_role_async using AnsibleWorkflow
- Loading branch information
Boris Odnopozov
committed
Oct 22, 2018
1 parent
84a80a0
commit a4b7d0a
Showing
4 changed files
with
99 additions
and
199 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
class ManageIQ::Providers::AnsiblePlaybookWorkflow < ManageIQ::Providers::AnsibleRunnerWorkflow | ||
def self.job_options(env_vars, extra_vars, playbook_options, timeout, poll_interval) | ||
{ | ||
:env_vars => env_vars, | ||
:extra_vars => extra_vars, | ||
:playbook_path => playbook_options[:playbook_path], | ||
:timeout => timeout, | ||
:poll_interval => poll_interval, | ||
} | ||
end | ||
|
||
def pre_playbook | ||
# A step before running the playbook for any optional setup tasks | ||
queue_signal(:run_playbook) | ||
end | ||
|
||
def run_playbook | ||
env_vars, extra_vars, playbook_path = options.values_at(:env_vars, :extra_vars, :playbook_path) | ||
|
||
response = Ansible::Runner.run_async(env_vars, extra_vars, playbook_path) | ||
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 | ||
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
class ManageIQ::Providers::AnsibleRoleWorkflow < ManageIQ::Providers::AnsibleRunnerWorkflow | ||
def self.job_options(env_vars, extra_vars, role_options, timeout, poll_interval) | ||
{ | ||
:env_vars => env_vars, | ||
:extra_vars => extra_vars, | ||
: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 | ||
} | ||
end | ||
|
||
def pre_role | ||
# A step before running the playbook for any optional setup tasks | ||
queue_signal(:run_role) | ||
end | ||
|
||
def run_role | ||
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 | ||
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
166 changes: 0 additions & 166 deletions
166
spec/models/manageiq/providers/ansible_runner_workflow_spec.rb
This file was deleted.
Oops, something went wrong.