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/

El lun, 28 jun 2021 a las 9:53, Yahia CHILALI (<yahia1...@gmail.com>)
escribió:

> Hi again,
> I can't feed the correct syntax... i tried with with_lines: cat
> /etc/ansible/group_vars/afyahia or loop: cat /etc/ansible/group_vars/afyahia
> Do you know the good attribute?
> ERROR! 'loop' is not a valid attribute for a Block
> ERROR! 'with_lines' is not a valid attribute for a Block
>
> Le lun. 28 juin 2021 à 12:56, david...@mycit.ie <david.fo...@mycit.ie> a
> écrit :
>
>> 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/
>>
>> On Monday, June 28, 2021 at 11:14:40 AM UTC+1 yahi...@gmail.com wrote:
>>
>>> 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
>>>
>>> --
>> You received this message because you are subscribed to the Google Groups
>> "Ansible Project" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to ansible-project+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/dc923fa6-4c2f-4590-9d5d-606d0e10e950n%40googlegroups.com
>> <https://groups.google.com/d/msgid/ansible-project/dc923fa6-4c2f-4590-9d5d-606d0e10e950n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CACRVY78MS_H42tS%3DYP-HRTn%2BUH6JDTGZ0pEw2XdL%3Dv5gbLCfMg%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CACRVY78MS_H42tS%3DYP-HRTn%2BUH6JDTGZ0pEw2XdL%3Dv5gbLCfMg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>


-- 

Roberto Paz

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAOWJX63WnR7KMpZ--%2BTDoX%2BiDB3_ei6920Ry8S35iCSrsYh5TQ%40mail.gmail.com.

Reply via email to