-
Notifications
You must be signed in to change notification settings - Fork 898
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17688 from Ladas/use_ansible_runner
Use ansible-runner instead of ansible-playbook
- Loading branch information
Showing
2 changed files
with
57 additions
and
4 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 |