Ansible win_reboot Module: Reboot Windows & Wait for Recovery (Guide)
By Luca Berton · Published 2024-01-01 · Category: troubleshooting
How to reboot Windows hosts with Ansible win_reboot module (ansible.windows.win_reboot). Restart Windows, wait for WinRM, set timeouts.

How to reboot remote Windows hosts with Ansible?
See also: Ansible Reboot Module: Restart Remote Hosts & Wait for Recovery (Guide)
Ansible reboot Windows hosts
Today we're talking about Ansible module win_reboot. The full name isansible.windows.win_reboot which means is part of the ansible.windows collection collection to target Windows host.
The purpose is to reboot a Windows machine, wait for it to go down, come back up, and respond to commands.
For non-Windows targets, use the ansible.builtin.reboot module instead.
Please note that the connection user must have the SeRemoteShutdownPrivilege Windows privilege enabled.
Parameters
- reboot_timeout float - 600
- msg string - "Reboot initiated by Ansible"
- connect_timeout float - 5
- pre_reboot_delay float - 2
- post_reboot_delay float - 0
- test_command string - "detect Windows Logon"
- boot_time_command string -
(Get-CimInstance -ClassName Win32_OperatingSystem -Property LastBootUpTime).LastBootUpTime.ToFileTime()
exit (Get-Service -Name Netlogon).Status -ne "Running"'
This module could return also the amount of time indeed for bootstrap process reading thow Windows system, specifically (Get-CimInstance -ClassName Win32_OperatingSystem -Property LastBootUpTime).LastBootUpTime.ToFileTime().
## Playbook Let's jump into a real-life playbook on how to reboot a Windows remote host with Ansible Playbook.
code
- win_reboot.yml
---
- name: win_reboot module Playbook
hosts: all
become: false
gather_facts: false
tasks:
- name: reboot host(s)
ansible.windows.win_reboot:
msg: "reboot by Ansible"
pre_reboot_delay: 5
post_reboot_delay: 10
execution
output$ ansible-playbook -i win/inventory troubleshooting/incompatiblesudo_fix.yml
PLAY [win_reboot module Playbook] *********************************************************************
TASK [reboot host(s)] *****************************************************************************
changed: [WindowsServer]
PLAY RECAP ****************************************************************************************
WindowsServer : ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
See also: Add Windows Registry on Windows-like systems - Ansible module win_regedit
Conclusion
Now you know how to reboot Windows hosts with Ansible.
Related Articles
Category: troubleshooting
Watch the video: Ansible win_reboot Module: Reboot Windows & Wait for Recovery (Guide) — Video Tutorial