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, Prompt, and Delay Execution (Complete Guide)

By Luca Berton · Published 2024-01-01 · Category: database-automation

How to use Ansible pause module to wait, prompt for input, and add delays. Interactive confirmations, timed pauses, and user prompts with playbook examples.

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

The ansible.builtin.pause module pause playbook execution. This guide covers all common use cases with practical playbook examples.

See also: Ansible pause Module: Wait for Input or Delay Playbook Execution

Timed Pause

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

- name: Wait 2 minutes
  ansible.builtin.pause:
    minutes: 2

Prompt for Confirmation

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

- name: Ask for version
  ansible.builtin.pause:
    prompt: "Enter the version to deploy"
  register: version_input

- name: Deploy version
  ansible.builtin.debug:
    msg: "Deploying {{ version_input.user_input }}"

See also: Ansible Custom Modules: Write Your Own Module in Python (Complete Guide)

Pause Until Enter

- name: Wait for manual step
  ansible.builtin.pause:
    prompt: "Complete the manual database backup, then press Enter to continue"

FAQ

How do I add a delay in Ansible?

Use ansible.builtin.pause: seconds=30 for a timed delay. For user interaction, use prompt to wait for Enter or capture input with register.

How do I prompt for user input in Ansible?

Use ansible.builtin.pause: prompt="Your question" with register: result. Access the input via result.user_input. For pre-play prompts, use vars_prompt instead.

See also: Ansible debug Module: Print Variables & Messages (Complete Guide)

Conclusion

The ansible.builtin.pause module is a versatile tool for pause playbook execution. Use the examples above as starting points and adapt them to your infrastructure needs.

Module Parameters Reference

ParameterRequiredDefaultDescription
secondsNoNumber of seconds to pause
minutesNoNumber of minutes to pause
promptNoMessage to display before pausing
echoNotrueShow user input when prompting

Pause for User Confirmation

- name: Confirm before proceeding
  ansible.builtin.pause:
    prompt: "This will deploy to PRODUCTION. Type 'yes' to continue"
  register: confirm
  when: env == "production"

- name: Abort if not confirmed
  ansible.builtin.fail:
    msg: "Deployment cancelled by user"
  when: confirm.user_input | default('') != 'yes'

Pause with Hidden Input (Passwords)

- name: Prompt for password
  ansible.builtin.pause:
    prompt: "Enter the database password"
    echo: false
  register: db_password

- name: Use the password
  ansible.builtin.debug:
    msg: "Password captured ({{ db_password.user_input | length }} chars)"

Timed Delay Between Tasks

- name: Wait for service to stabilize
  ansible.builtin.pause:
    seconds: 30
    prompt: "Waiting 30 seconds for service to stabilize..."

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

Complete Playbook: Rolling Deployment with Pauses

---
- name: Rolling deployment with safety pauses
  hosts: webservers
  serial: 1
  become: true

  tasks:
    - name: Pull latest application code
      ansible.builtin.git:
        repo: https://github.com/example/app.git
        dest: /opt/app
        version: main

    - name: Restart application service
      ansible.builtin.service:
        name: app
        state: restarted

    - name: Wait for health check
      ansible.builtin.uri:
        url: "http://{{ inventory_hostname }}:8080/health"
        status_code: 200
      register: health
      retries: 10
      delay: 5
      until: health.status == 200

    - name: Pause between hosts for monitoring
      ansible.builtin.pause:
        seconds: 60
        prompt: "Host {{ inventory_hostname }} deployed. Waiting 60s before next host..."

Pause vs wait_for

Featurepausewait_for
User interactionYes (prompt)No
Condition-basedNoYes (port, file, regex)
Fixed delayYesYes (timeout)
Use caseHuman approval, timed delaysWait for ports, files, services

When should I use pause vs wait_for?

Use ansible.builtin.pause for human interaction (confirmations, password input) or simple timed delays. Use ansible.builtin.wait_for when you need to wait for a condition like a port opening or a file appearing.

Does pause work in automated pipelines?

Timed pauses (seconds/minutes) work fine in CI/CD. Prompt-based pauses will hang in non-interactive environments — use when conditions to skip them in automated runs.

Category: database-automation

Browse all Ansible tutorials · AnsiblePilot Home