Are 'include:' loops possivel with output of a command?

Hello,

I could neither make it work, nor find a clear explanation, on whether it is possible to make a include loop
with with_items: taking a list values produced as the output of another command.

The following works:

command: /usr/bin/something
register: result

debug: msg=“{{item}}”
with_items: ${result.stdout_lines}

However I could not manage the following to work:

command: /usr/bin/something
register: result

include: another_playbook.yml <------ this one has 5 actions that must be executed in a row for each target
with_items: ${result.stdout_lines}

It fails with message:
ERROR: with_items expects a list

My concrete demand is that I have in the included playbook, actions that must be executed in sequence for each target, while targets are not known
util runtime. So I could not use multiple actions, each one with a ‘with_items: with_items: ${result.stdout_lines}’, because the second action in
“another_playbook” should only be executed for the next item if all actions in the playbook have succeeded for the previous item.

Is there an elegant way of doing this with playbooks?

Thanks in advance for any hints.

Best regards,
Luciano Cavalheiro

Nope, not possible.

includes cannot use “with” operations like that because the tasks must be the same in number and form (save variables) for all targets, and are precomputed.

You can of course take that data and use that loop information in one common task file “more_tasks.yml”

BTW, when you are including tasks, those are tasks, a playbook is something that starts with “- hosts: foo” and is higher level.

Thanks for the answer.

I managed it to work somewhat following your hint: created
a top playbook which includes another one that updates a
file that will be loaded by the next play in that top playbook.