ansible.windows icon indicating copy to clipboard operation
ansible.windows copied to clipboard

win_reboot: pending reboot check

Open ghost opened this issue 4 years ago • 8 comments

SUMMARY

Hello, Is it real to remake functionality of win_reboot like PendingReboot DSC resource works? Reboot only if reboot is pending, and use force key to force reboot

PendingReboot checks:

  • reboots triggered by the CCM ConfigMgr client
  • reboots triggered by Computer renames
  • pending file rename reboots
  • reboots triggered by Windows Update
  • reboots triggered by the Component-Based Servicing component
ISSUE TYPE
  • Feature Idea
COMPONENT NAME

win_reboot

ADDITIONAL INFORMATION

https://docs.microsoft.com/en-us/powershell/scripting/dsc/configurations/reboot-a-node?view=powershell-7.1 https://adamtheautomator.com/pending-reboot-registry-windows/

- name: Reboot the machine if it expects but skips hosts rename pending reboot check
  ansible.windows.win_reboot:
    post_reboot_delay: 120
    skip_pending_computer_rename: true
- name: No checks, just reboot
  ansible.windows.win_reboot:
    post_reboot_delay: 120d
    force: true

ghost avatar Feb 12 '21 16:02 ghost

As proposed, this would introduce a serious breaking change and (as it's altering the default behavior) would necessarily require a rewrite everywhere it is used.

Could you modify your request in such a way as to not alter the expected result of a playbook already in use?

My personal thought is that when I call win_reboot, I want and expect the target to reboot; I do not want or expect it to perform additional logic tests.

mwtrigg avatar Feb 13 '21 17:02 mwtrigg

Ok, mb it better looks like this:

- name: Reboot the machine if it expects but skips hosts rename pending reboot check
  ansible.windows.win_reboot:
    post_reboot_delay: 120
    if_pending: true
    if_pending_skip:
    - computer_rename

new bool parameter if_pending (default: false) used for intelligent reboot control new list parameter if_pending_skip used for skip pending reboot requirements. if_pending_skip list parameters:

   cmm_client_sdk
   component_based_servicing
   computer_rename
   file_rename
   windows_update

with this, you can keep the old win_reboot functionality without rewriting everything where it is used and add new "smart" behavior.

ghost avatar Feb 19 '21 07:02 ghost

While I'm not 100% against this idea I would be concerned about the implementation. There are a lot of things that would need to be checked and it could change at any moment in a Windows release. There could be other paths that people may want to add to the logic but may produce false positives. Some of the other checks that have an actual proper API from Windows to denote this info I would be less concerned about.

jborean93 avatar Mar 07 '21 22:03 jborean93

These 5 things that I indicated for checking have not changed for many years (since 2013 - https://devblogs.microsoft.com/scripting/determine-pending-reboot-statuspowershell-style-part-1/). These are the time-tested default flags for pending reboot. I do not agree that this will change at any time with the next release. Any other checks that people want to add are custom checks and should not be used in this module.

ghost avatar Mar 17 '21 08:03 ghost

Hey, i found a Module https://github.com/informatique-cdc/ansible-role-win_pending_reboot. Maybe we can use as an example how we integrate the function to the collection? In my opinion it is a must-have.

florianow avatar Jul 09 '21 12:07 florianow

I'm currently dealing with this issue as well and believe it would be better to design this feature request into this win reboot module. there are 3 registry flags that indicate if a reboot is pending on windows. Which means: option 1: we have to write 3 statements and register facts for each one and then write an if statement if any of those 3 registered values are true then register a value of reboot required

or

There is a reboot pending module that can be installed on every host (which checks these values and returns true or false which can be validated if installed, and installed / ran to check for pending reboot. (which goes outside of ansible to control the logic and requires the ability to install modules into powershell (just left shifting the hassle in my opinion).

I also agree this is a needed feature.

Rolroak avatar Sep 24 '21 18:09 Rolroak

Microsoft has a PowerShell module that does this for their MS Exchange Server Support Scripts, maybe that could be adapted? https://github.com/microsoft/CSS-Exchange/blob/main/Shared/Get-ServerRebootPending.ps1

abruening-iwt avatar May 12 '22 11:05 abruening-iwt

I had some free time and implemented a module to check pending reboots flags which partially solves the problem described in this issue. If you're still interested in solving the problem described here, please see https://github.com/ansible-collections/community.windows/pull/451

ghost avatar Oct 16 '22 12:10 ghost