Skip to content

Commit

Permalink
Merge pull request #21414 from agrare/handle_ansible_runner_exceptions
Browse files Browse the repository at this point in the history
Handle ansible runner exceptions in the AnsibleRunnerWorkflow
  • Loading branch information
Fryguy authored Sep 1, 2021
2 parents d74443e + 34a688e commit ee52383
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/models/manageiq/providers/ansible_runner_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def execute

route_signal(:poll_runner)
end
rescue => err
route_signal(:abort, "Failed to run ansible #{execution_type}: #{err}", "error")
end

def poll_runner
Expand Down
10 changes: 9 additions & 1 deletion lib/ansible/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,15 @@ def wait_for(path, timeout: 10.seconds)
path_created.set if added.include?(path) || modified.include?(path)
end

thread = Thread.new { listener.start }
thread = Thread.new do
listener.start
rescue ArgumentError => err
# If the main thread raises an exception immediately it is possible
# for the ensure block to call `listener.stop` before this thread
# begins its execution resulting in an ArgumentError due to the state
# being `:stopped`
raise unless err.message.include?("cannot start from state :stopped")
end

begin
res = yield
Expand Down

0 comments on commit ee52383

Please sign in to comment.