need help to configure a loop

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

Hi,

Have you tried using the Block function of Ansible?

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/

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/