AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,400 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.

Popular Topics

About Luca Berton

Luca Berton is an Ansible automation expert, author of 8 Ansible books published by Apress and Leanpub including "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example", and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.

Ansible pause Module: Wait for Input or Delay Playbook Execution

By Luca Berton · Published 2024-01-01 · Category: troubleshooting

How to pause Ansible playbook execution with the pause module (ansible.builtin.pause). Wait for user input, add delays between tasks, set timeout.

Ansible pause Module: Wait for Input or Delay Playbook Execution

How to pause a playbook execution for a certain amount of time with Ansible?

I'm going to show you a live Playbook with some simple Ansible code. I'm Luca Berton and welcome to today's episode of Ansible Pilot

See also: Ansible synchronize Module: Rsync Files & Directories Between Hosts

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.

## Playbook Let's jump in a real-life Ansible Playbook to pause a playbook execution.

code

• pause.yml
---
- name: pause module Playbook
  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 Playbook/inventory pause/pause.yml
PLAY [pause module Playbook] **************************************************************************
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 Playbook/inventory pause/pause.yml
PLAY [pause module Playbook] **************************************************************************
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 Playbook/inventory pause/pause.yml
PLAY [pause module Playbook] **************************************************************************
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

code with ❤️ in GitHub

See also: Ansible pause Module: Wait, Prompt, and Delay Execution (Complete Guide)

Conclusion

Now you know how to pause a playbook execution for certain amount of time with Ansible.

Pause for Duration

- name: Wait 30 seconds for service startup
  ansible.builtin.pause:
    seconds: 30

- name: Wait 5 minutes for DNS propagation ansible.builtin.pause: minutes: 5

See also: Add Windows Registry on Windows-like systems - Ansible module win_regedit

Pause for User Input

- name: Confirm before proceeding
  ansible.builtin.pause:
    prompt: "Press Enter to continue or Ctrl+C to abort"

- name: Get user input ansible.builtin.pause: prompt: "Enter the deployment version" register: version_input

- debug: msg: "Deploying version: {{ version_input.user_input }}"

Approval Gate

- name: Show deployment plan
  debug:
    msg: |
      Deploying to: {{ ansible_play_hosts | join(', ') }}
      Version: {{ app_version }}
      Environment: {{ env }}

- name: Manual approval ansible.builtin.pause: prompt: "Review the plan above. Type 'yes' to proceed" register: approval

- name: Abort if not approved ansible.builtin.fail: msg: "Deployment cancelled by user" when: approval.user_input != 'yes'

Wait for Service

# Better alternative to pause for services
- name: Wait for port to be available
  ansible.builtin.wait_for:
    port: 8080
    delay: 5
    timeout: 60

- name: Wait for URL to respond ansible.builtin.uri: url: http://localhost:8080/health register: result retries: 12 delay: 5 until: result.status == 200

Deployment Patterns

Rolling deploy with pause

- hosts: webservers
  serial: 1
  tasks:
    - name: Deploy
      import_tasks: deploy.yml

- name: Verify deployment uri: url: "http://{{ inventory_hostname }}:8080/health" delegate_to: localhost

- name: Pause between servers pause: seconds: 10 prompt: "{{ inventory_hostname }} deployed. Waiting before next..."

Drain connections before shutdown

- name: Remove from load balancer
  uri:
    url: "http://lb/api/disable/{{ inventory_hostname }}"
    method: POST
  delegate_to: localhost

- name: Wait for connections to drain pause: seconds: 30

- name: Stop service service: name: myapp state: stopped

pause vs wait_for

| Module | Use Case | |--------|----------| | pause | Fixed delay or user input | | wait_for | Wait for port/file/condition | | wait_for_connection | Wait for SSH to be available | | uri + until | Wait for HTTP endpoint |

FAQ

Does pause work in AWX/AAP?

Time-based pauses work. Prompts for user input use AWX's approval workflow instead of terminal input.

How do I skip pauses in CI/CD?

- pause:
    seconds: 30
  when: not ci_mode | default(false)
ansible-playbook site.yml -e ci_mode=true

Can I pause with a countdown?

The pause module shows elapsed time. For a visual countdown, use shell: sleep or a loop with decreasing delays.

Ansible inventory groups and variablesconfiguring Windows services via Ansible

Category: troubleshooting

Watch the video: Ansible pause Module: Wait for Input or Delay Playbook Execution — Video Tutorial

Browse all Ansible tutorials · AnsiblePilot Home