-
Notifications
You must be signed in to change notification settings - Fork 900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use ansible-runner instead of ansible-playbook #17688
Changes from 6 commits
e214bf2
7bc49ac
c883cc8
3afb737
ce9af21
b075243
5e9738f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is stderr not going to be json encoded? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we might do that later, right now it always returns "", so I am not sure what the format will be. Might be the same as the stdout There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need the return here? I think it will actually throw an exception:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see the exception but I can remove it