forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresponse.rb
36 lines (30 loc) · 943 Bytes
/
response.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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