How to create a nicer pause...

251 views
Skip to first unread message

Krist van Besien

unread,
Sep 19, 2016, 1:18:10 PM9/19/16
to Ansible Project
Hi all,

In one of my playbooks I need to build in a fairly long pause.

So I have this task:

- name: Pause for 20 minutes
  pause: minutes=20

This works, but has the disadvantage that for 20 minutes nothing appears to happen on the screen. I would like to give a bit of feedback. Like a message "still waiting, x minutes to go" every 30 seconds or so. What would be the best way to do this?

Krist

Kai Stian Olstad

unread,
Sep 19, 2016, 3:21:25 PM9/19/16
to ansible...@googlegroups.com
It's not pretty, but it gives a feedback every 30 seconds.

- name: Pause
pause:
seconds=30
with_sequence: start=40 end=0 stride=-1

--
Kai Stian Olstad

Krist van Besien

unread,
Sep 21, 2016, 8:09:37 AM9/21/16
to Ansible Project, ansible-pr...@olstad.com

That works. But this is indeed not that pretty. Is there a way to get rid of the prompt?

I think I might in stead create a loop that just executes "sleep 30"...

Krist

Kai Stian Olstad

unread,
Sep 21, 2016, 8:48:12 AM9/21/16
to ansible...@googlegroups.com
No.


> I think I might in stead create a loop that just executes "sleep 30"...

This is a solution that looks nice, the downside is it does 40 includes
and creates 40 dummy tasks.


pause.yml
---
- name: "{{ item | int / 2 }} minutes left"
command: sleep 30
changed_when: false


In the playbook:

- include: pause.yml
with_sequence: start=40 end=1 stride=-1


--
Kai Stian Olstad

Josh Smift

unread,
Sep 21, 2016, 9:04:56 AM9/21/16
to ansible...@googlegroups.com
How about wait_for?

- name: count down forty 30-second intervals
wait_for: timeout=30
with_sequence: start=40 end=0 stride=-1

That gives me output like this:

TASK [count down forty 30-second intervals]
*************************************
ok: [localhost] => (item=40)
ok: [localhost] => (item=39)

etc.

-Josh (j...@care.com)

(apologies for the automatic corporate disclaimer that follows)

This email is intended for the person(s) to whom it is addressed and may contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, distribution, copying, or disclosure by any person other than the addressee(s) is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and delete the message and any attachments from your system.
Reply all
Reply to author
Forward
0 new messages