-
Notifications
You must be signed in to change notification settings - Fork 898
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e214bf2
Use ansible-runner instead of ansible-playbook
Ladas 7bc49ac
Use mktmpdir to clean up ansible-runner files after the run
Ladas c883cc8
Deal with output which is JSON per line
Ladas 3afb737
Add a result object so we can easily extend it in the future
Ladas ce9af21
Simplify the mkdir
Ladas b075243
Return integer return code
Ladas 5e9738f
Remove extra return and reformat
Ladas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is stderr not going to be json encoded?
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
👍