Loop over multiple tasks

27 views
Skip to first unread message

Jamie Addessi

unread,
Dec 5, 2019, 1:13:17 PM12/5/19
to Ansible Project
Hello,

Is it possible in Ansible to loop over multiple tasks?

Something like:

    - loop: "{{ mylist }}"

      - name: Task 1
        do something with item step 1

      - name: Task 2
        do something with item step 2

      - name: Task 3
        do something with item step 3

The only way I've found to accomplish this is to call out to a tasks file within the loop, and include all 3 tasks there.  But it would be nicer to be able to do it in a single playbook.
      - name: Loop control
        include_tasks: "tasks.yml"
        loop: "{{ mylist }}"

Thanks for any feedback!

Kai Stian Olstad

unread,
Dec 5, 2019, 1:22:09 PM12/5/19
to ansible...@googlegroups.com
On 05.12.2019 19:13, Jamie Addessi wrote:
> The only way I've found to accomplish this is to call out to a tasks file
> within the loop, and include all 3 tasks there. But it would be nicer to
> be able to do it in a single playbook.
> - name: Loop control
> include_tasks: "tasks.yml"
> loop: "{{ mylist }}"

This is the only way to do it unfortunately.


--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages