Thanks Brian for helping me understand how with item task work under the 
hoods.

I was expecting "with_items" to work as different tasks, as per 
documentation "To save some typing, repeated tasks can be written in 
short-hand like so 
<http://docs.ansible.com/ansible/latest/playbooks_loops.html#standard-loops>
:" 

thus I was expecting it to be "transformed" to something like this

- name: Long task iteration 1
win_shell: (0..5) | foreach { (date).ToString("hh:mm:ss:ffff");Start-Sleep 
-Seconds 1 }
when: "(( ansible_play_batch.index(inventory_hostname) % (( play_hosts | 
length ) / 2 )) | round) == 0"
- name: Long task iteration 2
win_shell: (0..5) | foreach { (date).ToString("hh:mm:ss:ffff");Start-Sleep 
-Seconds 1 }
when: "(( ansible_play_batch.index(inventory_hostname) % (( play_hosts | 
length ) / 2 )) | round) == 1"
- name: Long task iteration 2
win_shell: (0..5) | foreach { (date).ToString("hh:mm:ss:ffff");Start-Sleep 
-Seconds 1 }
when: "(( ansible_play_batch.index(inventory_hostname) % (( play_hosts | 
length ) / 2 )) | round) == 2"

which has my desired behaviour,

>From what you told me I understand that loops are executed as a single task 
for each host

---
Guillem

On Friday, February 9, 2018 at 2:47:12 AM UTC+1, Brian Coca wrote:
>
> No, in a loop everything executes sequentially, but EACH host executes 
> their own version of the task AND the loop in parallel. 
>
> debug will give you misleading results as it is a 'local' process and 
> probably finishes before other forks can start, once you intorduce the 
> delay of remote tranfer+execution you start seeing the real and 
> correct behaviour. 
>
> You might want to put the task in a play with 'serial' to handle the 
> 'global limit' correctly. 
>
>
> -- 
> ---------- 
> Brian Coca 
>

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/55cf6423-9879-4feb-b7fb-c2f133531536%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to