Skip to content

Commit

Permalink
Deal with output which is JSON per line
Browse files Browse the repository at this point in the history
Deal with output which is JSON per line and for now, deal with
possible non json lines.
  • Loading branch information
Ladas committed Jul 13, 2018
1 parent 98eb2cc commit 80a2352
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/ansible/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,21 @@ def run_via_cli(env_vars, extra_vars, playbook_path)
mkdir(base_dir + '/project') # without this, there is a silent fail of the ansible-runner command see https://github.com/ansible/ansible-runner/issues/88

result = AwesomeSpawn.run!(ansible_command(base_dir), :env => env_vars, :params => [{:cmdline => "--extra-vars '#{JSON.dump(extra_vars)}'", :playbook => playbook_path}])
JSON.parse(result.output)

parsed_stdout = []

# output is JSON per new line
result.output.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

Expand Down

0 comments on commit 80a2352

Please sign in to comment.