Given what Brian pointed out, you can achieve the same effect by using 
include_tasks where the tasks file contains the task you want to loop over 
followed by a conditional invocation of the pause module. Here's a sample 
playbook with some data. Note that the 3rd item has a non-zero pause value.
---
# inc-loop-demo-main.yml
- hosts: localhost
  vars:
    aaa:
    - {able: fee, baker: fie, charlie: foe, pause: 0 }
    - {able: nee, baker: nie, charlie: noe, pause: 0 }
    - {able: see, baker: sie, charlie: soe, pause: 5 }
    - {able: zee, baker: zie, charlie: zoe, pause: 0 }
  tasks:
  - name: Dump data
    debug:
      msg: "{{ aaa }}"

  - name: Loop over aaa calling inc-loop-demo-tasks.yml
    include_tasks: inc-loop-demo-tasks.yml
    loop: "{{ aaa }}"

and the task file that it includes:
---
# inc-loop-demo-tasks.yml
- name: show item
  debug:
    msg: "able: {{ item.able }}, baker: {{ item.baker }}, charlie: {{ 
item.charlie }}, pause: {{ item.pause }}"

- name: optional delay after prior tasks
  pause:
    seconds: "{{ item.pause }}"
  when: item.pause > 0

Here's a subset of the output:
TASK [show item] *******************************************
ok: [localhost] => 
  msg: 'able: nee, baker: nie, charlie: noe, pause: 0'

TASK [optional delay after prior tasks] ********************
skipping: [localhost]

TASK [show item] *******************************************
ok: [localhost] => 
  msg: 'able: see, baker: sie, charlie: soe, *pause: 5*'

TASK [optional delay after prior tasks] ********************
*Pausing for 5 seconds*
(ctrl+C then 'C' = continue early, ctrl+C then 'A' = abort)
ok: [localhost]

TASK [show item] *******************************************
ok: [localhost] => 
  msg: 'able: zee, baker: zie, charlie: zoe, pause: 0'

TASK [optional delay after prior tasks] ********************
skipping: [localhost]

PLAY RECAP *************************************************
localhost: ok=11   changed=0    unreachable=0    failed=0
      skipped=3    rescued=0    ignored=0   

On Tuesday, November 2, 2021 at 4:02:12 PM UTC-4 Brian Coca wrote:

> pause gets calculated before the looping starts so it cannot be set per 
> item
>
> -
> ----------
> 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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/a7020915-95f4-4f4c-8001-81a7bbce7912n%40googlegroups.com.

Reply via email to