-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a result object so we can easily extend it in the future
Add a result object so we can easily extend it in the future
- Loading branch information
Showing
2 changed files
with
42 additions
and
15 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module Ansible | ||
class Runner | ||
class Response | ||
include Vmdb::Logging | ||
|
||
attr_reader :return_code, :stdout, :stderr, :parsed_stdout | ||
|
||
def initialize(return_code:, stdout:, stderr:) | ||
@return_code = return_code | ||
@stdout = stdout | ||
@parsed_stdout = parse_stdout(stdout) | ||
@stderr = stderr | ||
end | ||
|
||
private | ||
|
||
def parse_stdout(stdout) | ||
parsed_stdout = [] | ||
|
||
# output is JSON per new line | ||
stdout.each_line do |line| | ||
# TODO(lsmola) we can remove exception handling when this is fixed | ||
# https://github.com/ansible/ansible-runner/issues/89#issuecomment-404236832 , so it fails early if there is | ||
# a non json line | ||
begin | ||
parsed_stdout << JSON.parse(line) | ||
rescue => e | ||
_log.warn("Couldn't parse JSON from: #{e}") | ||
end | ||
end | ||
|
||
parsed_stdout | ||
end | ||
end | ||
end | ||
end |