Bolt task allow for returning structured output per the documentation:
To return structured data from your task, print only a single JSON object to stdout in your task.
#!/usr/bin/env python
import json
import sys
minor = sys.version_info
result = { "major": sys.version_info.major, "minor": sys.version_info.minor }
json.dump(result, sys.stdout)
Which in my Ruby task would look like this:
#!/usr/bin/env ruby
require 'json'
major, minor, patch = RUBY_VERSION.split('.')
result = { 'major' => major, 'minor' => minor }
puts result.to_json
Which works, and I can access the returned data as a structured value in the caller like this:
$data = run_task('foo::bar', 'localhost', {'_catch_errors'=>true}).first.value()
However, if I return an array from the task
require 'json'
result = [ '192.168.1.1', '192.168.1.2' ]
puts result.to_json
that doesn't seem to work, because when I output $data
it seems to be "regular" output instead of structured data I expected:
{_output => ["192.168.1.1","192.168.1.2"]
}
Wrapping the array in curly brackets doesn't help either.