ansible.windows.win_reboot_info module – Get reboot status information for a Windows host

Note

This module is part of the ansible.windows collection (version 3.7.0).

It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install ansible.windows.

To use it in a playbook, specify: ansible.windows.win_reboot_info.

New in ansible.windows 3.8.0

Synopsis

  • Returns information about the last boot time and whether a reboot is pending on the target Windows host.

  • A pending reboot can be caused by Windows Update, Component Based Servicing, pending file rename operations, domain join operations, or Server Manager component changes.

See Also

See also

ansible.windows.win_reboot

Reboot a windows machine.

Examples

- name: Get reboot info
  ansible.windows.win_reboot_info:
  register: reboot_info

- name: Reboot if required
  ansible.windows.win_reboot:
  when: reboot_info.reboot_required

- name: Display last boot time
  ansible.builtin.debug:
    msg: "Last boot: {{ reboot_info.last_reboot.time }}"

- name: Show who initiated the last reboot
  ansible.builtin.debug:
    msg: >-
      Last reboot was initiated by {{ reboot_info.last_reboot.details.initiated_by }}
      via {{ reboot_info.last_reboot.details.process }}
      with comment: {{ reboot_info.last_reboot.details.comment }}
  when: reboot_info.last_reboot.details is not none

- name: Show pending reboot sources
  ansible.builtin.debug:
    msg: "Pending reboot due to: {{ reboot_info.reboot_required_reasons | map(attribute='source') | list }}"
  when: reboot_info.reboot_required

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key

Description

last_reboot

dictionary

Information about the last system boot.

Returned: always

details

dictionary

Details about the most recent shutdown or restart event from the Windows Event Log.

This is gathered from Event ID 1074 in the System log.

Will be null if no shutdown event was found in the event log.

Returned: success

comment

string

The comment or message provided when the reboot was initiated.

Returned: success

Sample: "Reboot initiated by Ansible"

event_time

string

The time the shutdown event was logged as an ISO 8601 UTC timestamp.

Returned: success

Sample: "2024-01-15T08:29:45Z"

initiated_by

string

The user account that initiated the reboot.

Returned: success

Sample: "DOMAIN\\admin"

process

string

The process that triggered the reboot.

Returned: success

Sample: "C:\\Windows\\system32\\shutdown.exe"

reason

string

The reason category for the reboot.

Returned: success

Sample: "Operating System: Recovery (Planned)"

reason_code

any

The shutdown reason code associated with the reboot, as recorded in the event log.

This is a 32-bit value combining the major reason, minor reason, and flag bits (for example the high bit indicates a planned shutdown).

This is normally returned as an integer, but may fall back to the raw value from the event log if it could not be parsed as an integer.

The Windows event viewer displays this value as a hexadecimal string (for example 0x80040002); this is equivalent to the integer returned here.

Returned: success

Sample: 2147745794

type

string

The type of action, such as restart, shutdown, or power off.

Returned: success

Sample: "restart"

time

string

The last boot time of the system as an ISO 8601 UTC timestamp.

Returned: success

Sample: "2024-01-15T08:30:00Z"

time_epoch

float

The last boot time as a Unix epoch timestamp in seconds.

Returned: success

Sample: 1705305000.0

reboot_required

boolean

Whether the system has a pending reboot from any source.

Returned: always

Sample: true

reboot_required_reasons

list / elements=dictionary

A list of sources that require a reboot.

Will be an empty list if no reboot is pending.

Returned: always

description

string

A human-readable description of why a reboot is pending.

Returned: success

Sample: "Windows Update has installed updates that require a reboot."

source

string

The source that requires a reboot.

Known sources are component_based_servicing, windows_update, pending_file_rename, pending_computer_rename, domain_join, server_manager.

Returned: success

Sample: "windows_update"

Authors

  • Mike Morency (@mikemorency)