Ansible - Pause or sleep in a playbook

by
Jeremy Canfield |
Updated: May 15 2024
| Ansible articles
If you are not familiar with modules, check out Ansible - Getting Started with Modules.
Both the pause module and delay parameter are used to create a pause or delay during task execution.
In this example, a 5 second pause is made after invoking the shell module.
---
- hosts: all
tasks:
- name: kill pid 12345
ansible.builtin.shell: kill -9 12345
- name: 5 second pause
ansible.builtin.pause:
seconds: 5
...
Something like this should be returned.
PLAY [all]
TASK [kill pid 12345]
changed: [server1.example.com]
changed: [server2.example.com]
changed: [server3.example.com]
TASK [3 second pause]
Pausing for 3 seconds
(ctrl+C then 'C' = continue early, ctrl+C then 'A' = abort)
PLAY RECAP
server1.example.com : ok=2 changed=1 unreachable=0 failed=0
server2.example.com : ok=2 changed=1 unreachable=0 failed=0
server3.example.com : ok=2 changed=1 unreachable=0 failed=0
Did you find this article helpful?
If so, consider buying me a coffee over at