How to loop over a block or multiple tasks Ansible

Posted by

One of the biggest shortcomings of the Ansible syntax is the ability to loop over a block with tasks in it. It is possible to loop over multiple arrays, nested objects etc. But looping over a set of tasks is not possible within the same playbook.

To be able to loop over a group of task, you can use the include playbook option. This will include the playbook for each item in your list / object. Like the following example:

main.yml playbook:

Include playbook ‘taskblock.yml’

The playbook result, including folder size.

Leave a Reply

Your email address will not be published. Required fields are marked *