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

**URL:** <https://forum.ansible.com/t/are-include-loops-possivel-with-output-of-a-command/13165>\
**Category:** Ansible Project\
**Created:** [July 19, 2013, 7:32pm UTC](https://forum.ansible.com/t/are-include-loops-possivel-with-output-of-a-command/13165 "2013-07-19T19:32:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lucc](https://avatars.discourse-cdn.com/v4/letter/l/34f0e0/32.png) [@lucc](https://forum.ansible.com/u/lucc)\
**Post date:** [July 19, 2013, 7:32pm UTC](https://forum.ansible.com/t/are-include-loops-possivel-with-output-of-a-command/13165/1 "2013-07-19T19:32:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [July 19, 2013, 7:53pm UTC](https://forum.ansible.com/t/are-include-loops-possivel-with-output-of-a-command/13165/2 "2013-07-19T19:53:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lucc](https://avatars.discourse-cdn.com/v4/letter/l/34f0e0/32.png) [@lucc](https://forum.ansible.com/u/lucc)\
**Post date:** [July 19, 2013, 10:26pm UTC](https://forum.ansible.com/t/are-include-loops-possivel-with-output-of-a-command/13165/3 "2013-07-19T22:26:28Z")

</div>

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.
