Pause execution - Ansible module pause
How to pause a playbook execution for a certain amount of minutes or seconds with Ansible.


How to pause a playbook execution for a certain amount of time with Ansible?
I’m going to show you a live demo with some simple Ansible code. I’m Luca Berton and welcome to today’s episode of Ansible Pilot
Ansible pause execution
Today we’re talking about the Ansible module pause
.
This module is also supported for Windows targets.
The full name is ansible.builtin.pause
, which means that is part of the collection of modules “builtin” with Ansible and shipped with it.
The default behavior is to pause with a prompt.
Pauses playbook execution for a set amount of time, or until a prompt is acknowledged.
Parameters
- minutes string - a positive number of minutes
- seconds string - a positive number of seconds
- prompt string - “Text message” -echo boolean - yes/no
All parameters are optional. The default behavior is to pause with a prompt. You could specify the amount of time using the parameters “minutes” and “seconds”. Starting in Ansible 2.2, if you specify 0 or negative for minutes or seconds, it will wait for 1 second, previously it would wait indefinitely. When minutes or seconds are specified, user input is not captured or echoed, regardless of the echo setting. I’ll cover the user input in another video.
The Best Resources For Ansible
Video Course
Printed Book
eBooks
- Ansible by Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps
- Ansible For Windows By Examples: 50+ Automation Examples For Windows System Administrator And DevOps
- Ansible For Linux by Examples: 100+ Automation Examples For Linux System Administrator and DevOps
- Ansible Linux Filesystem By Examples: 40+ Automation Examples on Linux File and Directory Operation for Modern IT Infrastructure
- Ansible For Containers and Kubernetes By Examples: 20+ Automation Examples To Automate Containers, Kubernetes and OpenShift
- Ansible For Security by Examples: 100+ Automation Examples to Automate Security and Verify Compliance for IT Modern Infrastructure
- Ansible Tips and Tricks: 10+ Ansible Examples to Save Time and Automate More Tasks
- Ansible Linux Users & Groups By Examples: 20+ Automation Examples on Linux Users and Groups Operation for Modern IT Infrastructure
- Ansible For PostgreSQL by Examples: 10+ Examples To Automate Your PostgreSQL database
- Ansible For Amazon Web Services AWS By Examples: 10+ Examples To Automate Your AWS Modern Infrastructure
demo
Let’s jump in a real-life Ansible Playbook to pause a playbook execution.
code
- pause.yml
---
- name: pause module demo
hosts: all
vars:
wait_seconds: 10
tasks:
- name: pause for {{ wait_seconds | int }} second(s)
ansible.builtin.pause:
seconds: "{{ wait_seconds | int }}"
- name: message
ansible.builtin.debug:
msg: "The end"
output
$ ansible-playbook -i demo/inventory pause/pause.yml
PLAY [pause module demo] **************************************************************************
TASK [Gathering Facts] ****************************************************************************
ok: [demo.example.com]
TASK [pause for 10 second(s)] *********************************************************************
Pausing for 10 seconds
(ctrl+C then 'C' = continue early, ctrl+C then 'A' = abort)
ok: [demo.example.com]
TASK [message] ************************************************************************************
ok: [demo.example.com] => {
"msg": "The end"
}
PLAY RECAP ****************************************************************************************
demo.example.com : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
output with manual continue (CTRL+C and “C”)
$ ansible-playbook -i demo/inventory pause/pause.yml
PLAY [pause module demo] **************************************************************************
TASK [Gathering Facts] ****************************************************************************
ok: [demo.example.com]
TASK [pause for 10 second(s)] *********************************************************************
Pausing for 10 seconds
(ctrl+C then 'C' = continue early, ctrl+C then 'A' = abort)
Press 'C' to continue the play or 'A' to abort
ok: [demo.example.com]
TASK [message] ************************************************************************************
ok: [demo.example.com] => {
"msg": "The end"
}
output with manual abort (CTRL+C and “A”)
$ ansible-playbook -i demo/inventory pause/pause.yml
PLAY [pause module demo] **************************************************************************
TASK [Gathering Facts] ****************************************************************************
ok: [demo.example.com]
TASK [pause for 10 second(s)] *********************************************************************
Pausing for 10 seconds
(ctrl+C then 'C' = continue early, ctrl+C then 'A' = abort)
Press 'C' to continue the play or 'A' to abort
fatal: [demo.example.com]: FAILED! => {"msg": "user requested abort!"}
NO MORE HOSTS LEFT ********************************************************************************
PLAY RECAP ****************************************************************************************
demo.example.com : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
Recap
Now you know how to pause a playbook execution for certain amount of time with Ansible. Subscribe to the YouTube channel, Medium, Website, Twitter, and Substack to not miss the next episode of the Ansible Pilot.
Academy
Learn the Ansible automation technology with some real-life examples in my
My book Ansible By Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps
Donate
Want to keep this project going? Please donate