Re: [ansible-project] In a loop everything executes at the same time?

2018-02-13 Thread Guillem Sola
Very interesting, so then each host individually needs 0 sec for the 
iterations it doesn't execute which ends up with all the hosts executing 
the tasks at the same time.

I was inspired by this 
comment https://github.com/ansible/ansible/issues/12170#issuecomment-283950548 
but now I understand it is not possible then.

Thanks



https://github.com/ansible/ansible/issues/12170#issuecomment-283950548

On Monday, February 12, 2018 at 11:31:19 PM UTC+1, Brian Coca wrote:
>
> kind of, the result is similar to what you expected but not the same, 
> a loop gets 'unrolled' into N tasks (1 per item) per host, but they 
> are grouped as a single task per host for the results. 
>
> The loop itself is sequential (within the same host) but in parallel 
> with the same task/loop with other hosts. 
>
>
>
>
> -- 
> -- 
> 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/73c62bf2-3203-4714-bc63-8174fa5a8695%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] In a loop everything executes at the same time?

2018-02-12 Thread Brian Coca
kind of, the result is similar to what you expected but not the same,
a loop gets 'unrolled' into N tasks (1 per item) per host, but they
are grouped as a single task per host for the results.

The loop itself is sequential (within the same host) but in parallel
with the same task/loop with other hosts.




-- 
--
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/CACVha7dgO%3DmLTvXbeMgm-uq2vc2FUVfUU04J8j6q6ZD60HxtsQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] In a loop everything executes at the same time?

2018-02-09 Thread Guillem Sola
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 

:" 

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:");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:");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:");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.


Re: [ansible-project] In a loop everything executes at the same time?

2018-02-08 Thread Brian Coca
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/CACVha7cuxo%3DqPDTbXZ2c7K7E0n6yDN_bpgEWvoOJ_YEq%2BxfyhA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] In a loop everything executes at the same time?

2018-02-08 Thread Guillem Sola
I want to limit the number of parllel executions for a certain task inside 
a playbook (I have some constrains with downloading artifacts)

In that way the rest of tasks wil execute in all hosts at the same time but 
when the download task executes it will be limited to batches of N.

For this I'm creating a sequence with the # of iterations needed. If I do 
this it seems to work quite well

- debug:
msg: "Sequence {{ item }} with modulus {{ (( 
ansible_play_batch.index(inventory_hostname) % (( play_hosts | length ) / 2 
)) | round) }}"
with_sequence: start=0 end={{ (( play_hosts | length ) / 2 ) | round (0, 
'floor') | int }}
loop_control:
pause: 5
when: "(( ansible_play_batch.index(inventory_hostname) % (( play_hosts | 
length ) / 2 )) | round) == (item | int)"

Output

TASK [debug] 

skipping: [PCT2EMFR0HP.pct2m.local] => (item=0) => {"changed": false, "item": 
"0", "skip_reason": "Conditional result was False"}
skipping: [PCT2EMFR0HQ.pct2m.local] => (item=0) => {"changed": false, "item": 
"0", "skip_reason": "Conditional result was False"}
skipping: [PCT2EMFR0HR.pct2m.local] => (item=0) => {"changed": false, "item": 
"0", "skip_reason": "Conditional result was False"}
ok: [PCT2EMFR0HO.pct2m.local] => (item=0) => {
"changed": false,
"item": "0",
"msg": "Sequence 0 with modulus 0.0"
}
skipping: [PCT2W00RDSH001.pct2m.local] => (item=0) => {"changed": false, 
"item": "0", "skip_reason": "Conditional result was False"}
ok: [PCT2EMFR0HP.pct2m.local] => (item=1) => {
"changed": false,
"item": "1",
"msg": "Sequence 1 with modulus 1.0"
}
skipping: [PCT2EMFR0HQ.pct2m.local] => (item=1) => {"changed": false, "item": 
"1", "skip_reason": "Conditional result was False"}
skipping: [PCT2EMFR0HO.pct2m.local] => (item=1) => {"changed": false, "item": 
"1", "skip_reason": "Conditional result was False"}
skipping: [PCT2W00RDSH001.pct2m.local] => (item=1) => {"changed": false, 
"item": "1", "skip_reason": "Conditional result was False"}
ok: [PCT2EMFR0HR.pct2m.local] => (item=1) => {
"changed": false,
"item": "1",
"msg": "Sequence 1 with modulus 1.0"
}
skipping: [PCT2EMFR0HP.pct2m.local] => (item=2) => {"changed": false, "item": 
"2", "skip_reason": "Conditional result was False"}
ok: [PCT2EMFR0HQ.pct2m.local] => (item=2) => {
"changed": false,
"item": "2",
"msg": "Sequence 2 with modulus 2.0"
}
skipping: [PCT2EMFR0HO.pct2m.local] => (item=2) => {"changed": false, "item": 
"2", "skip_reason": "Conditional result was False"}
skipping: [PCT2EMFR0HR.pct2m.local] => (item=2) => {"changed": false, "item": 
"2", "skip_reason": "Conditional result was False"}
ok: [PCT2W00RDSH001.pct2m.local] => (item=2) => {
"changed": false,
"item": "2",
"msg": "Sequence 2 with modulus 2.0"
}

But if I execute something in the remote server (in this case just a sleep 
or a download) it seems that at the end everything is executed in parallel. 
See output generated times for each task, there should be some timespan 
seconds between loop iterations

- name: Download at ratio three at most
win_get_url:
url: http://ipv4.download.thinkbroadband.com/100MB.zip
dest: c:/ansible/100MB.zip
force: yes
# win_shell: (0..5) | foreach { 
(date).ToString("hh:mm:ss:");Start-Sleep -Seconds 1 }
with_sequence: start=0 end={{ (( play_hosts | length ) / 2 ) | round (0, 
'floor') | int }}
when: "(( ansible_play_batch.index(inventory_hostname) % (( play_hosts | 
length ) / 2 )) | round) == (item | int)"

Output

TASK [Download at ratio three at most] 
**
skipping: [PCT2EMFR0HP.pct2m.local] => (item=0) => {"changed": false, "item": 
"0", "skip_reason": "Conditional result was False"}
skipping: [PCT2EMFR0HQ.pct2m.local] => (item=0) => {"changed": false, "item": 
"0", "skip_reason": "Conditional result was False"}
skipping: [PCT2EMFR0HQ.pct2m.local] => (item=1) => {"changed": false, "item": 
"1", "skip_reason": "Conditional result was False"}
skipping: [PCT2EMFR0HR.pct2m.local] => (item=0) => {"changed": false, "item": 
"0", "skip_reason": "Conditional result was False"}
skipping: [PCT2W00RDSH001.pct2m.local] => (item=0) => {"changed": false, 
"item": "0", "skip_reason": "Conditional result was False"}
skipping: [PCT2W00RDSH001.pct2m.local] => (item=1) => {"changed": false, 
"item": "1", "skip_reason": "Conditional result was False"}
changed: [PCT2EMFR0HP.pct2m.local] => (item=1) => {"changed": true, "cmd": 
"(0..5) 
| foreach { (date).ToString(\"hh:mm:ss:\");Start-Sleep -Seconds 1 }", 
"delta": "0:00:06.531287", "end": "2018-02-08 10:26:58.403828", "item": "1", 
"rc": 0, "start": "2018-02-08 10:26:51.872540", "stderr": "", "stderr_lines": 
[], "stdout":