# need help to configure a loop

**URL:** <https://forum.ansible.com/t/need-help-to-configure-a-loop/35423>\
**Category:** Ansible Project\
**Created:** [June 28, 2021, 10:14am UTC](https://forum.ansible.com/t/need-help-to-configure-a-loop/35423 "2021-06-28T10:14:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![y\_c](https://avatars.discourse-cdn.com/v4/letter/y/65b543/32.png) [@y\_c](https://forum.ansible.com/u/y_c)\
**Post date:** [June 28, 2021, 10:14am UTC](https://forum.ansible.com/t/need-help-to-configure-a-loop/35423/1 "2021-06-28T10:14:40Z")

</div>

Hello guys,  
I need to run loop with a file but run all tasks item by item. Here is my conf:

- name: test  
hosts: yo

tasks:

- name: task 1  
win\_uri:  
url: https://{{ frontsrc }}/{{ item }}/  
with\_lines: cat /etc/ansible/group\_vars/afyahia

- name: Task 2  
win\_uri:  
url: https://{{ frontsrc }}.{{ item }}/  
with\_lines: cat /etc/ansible/group\_vars/afyahia

in afyahia file, i have:  
appli1  
appli2  
…  
applin

If i run the playbook it’s running like:  
task 1  
appli1  
appli2  
…  
…

task 2  
appli1  
appli2  
…

I would like to run it like this:  
task 1  
appli1

task 2  
appli1

task 1  
appli2

task 2  
appli2

task 1  
…

task 2  
…

Is it possible?  
thx

---

<div class="post-metadata">

**Author:** ![David\_Foley](https://avatars.discourse-cdn.com/v4/letter/d/9e8a1a/32.png) [@David\_Foley](https://forum.ansible.com/u/David_Foley)\
**Post date:** [June 28, 2021, 10:56am UTC](https://forum.ansible.com/t/need-help-to-configure-a-loop/35423/2 "2021-06-28T10:56:44Z")

</div>

Hi,

Have you tried using the Block function of Ansible?

[https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_blocks.html](https://docs.ansible.com/ansible/latest/user_guide/playbooks_blocks.html)

[https://ericsysmin.com/2019/06/20/how-to-loop-blocks-of-code-in-ansible/](https://ericsysmin.com/2019/06/20/how-to-loop-blocks-of-code-in-ansible/)

---

<div class="post-metadata">

**Author:** ![Roberto\_J\_R\_Paz](https://avatars.discourse-cdn.com/v4/letter/r/d2c977/32.png) [@Roberto\_J\_R\_Paz](https://forum.ansible.com/u/Roberto_J_R_Paz)\
**Post date:** [June 28, 2021, 3:00pm UTC](https://forum.ansible.com/t/need-help-to-configure-a-loop/35423/3 "2021-06-28T15:00:45Z")

</div>

You can’t apply a loop to a block. A possible caveat for that is to include the code of the block as a separated playbook and run the loop on that.

Example here: [https://ericsysmin.com/2019/06/20/how-to-loop-blocks-of-code-in-ansible/](https://ericsysmin.com/2019/06/20/how-to-loop-blocks-of-code-in-ansible/)
