run_task()
returns a ResultSet
, but if you inspect the $results
after sequential execution (e.g. via notice($results)
) you'll see that the each
method mangled the list of ResultSet
objects into a string array. To preserve the ResultSet
objects from the task execution you need to replace each
with map
.
That alone won't solve the problem, though, because you'd then have an array of ResultSet
objects that still doesn't have an ok
method. To fix this you need to construct a new ResultSet
object from all the returned results. The canonical approach to that would be to fetch all the results from each returned ResultSet
object, then flatten the resulting jagged array before constructing the new ResultSet
object. flatten()
is needed here because without it you'd get another error that the ResultSet
constructor doesn't accept a tuple as its argument.
$results = ResultSet(flatten($nodes.map |$node| {
run_task('my::job', $node, $params).results
}))
However, in your particular case it would probably suffice to just pick the first result from each set, since you're running the task individually on each node so that each set will most likely contain just a single result anyway.
$results = ResultSet($nodes.map |$node| {
run_task('my::job', $node, $params).first
})