rgl / packer-plugin-windows-update

Packer plugin for installing Windows updates
Mozilla Public License 2.0
295 stars 71 forks source link

Windows 2022 - packer-windows-update-elevated.ps1 repeatedly fails #142

Open bronandrews opened 2 months ago

bronandrews commented 2 months ago

Hi, I am using this plugin v0.15.0 to install updates during a fresh Windows 2022 build. I'm including Important updates only, with the following syntax.

provisioner "windows-update" {
      search_criteria = "AutoSelectOnWebSites=1 and IsInstalled=0"
      filters = [
         "include:$true"
      ]
}

It finds new Updates and seems to carry out the install, but consistently fails when trying to exit Windows Modules Installer... sample output log looks like...

_2024/05/09 14:33:10 ui: hyperv-iso.appbase: Waiting for the Windows Modules Installer to exit... 2024/05/09 14:33:56 ui: hyperv-iso.appbase: Waiting for operation to complete (system performance: 4% cpu; 13% memory)... memory)... 2024/05/09 14:41:05 ui: hyperv-iso.appbase: Waiting for operation to complete (system performance: 1% cpu; 13% memory)... 2024/05/09 14:41:55 packer-plugin-hyperv_v1.1.3_x5.0_windows_amd64.exe plugin: 2024/05/09 14:41:55 [ERROR] Remote command exited with '1': PowerShell -ExecutionPolicy Bypass -OutputFormat Text -File C:/Windows/Temp/packer-windows-update-elevated.ps1 2024/05/09 14:41:55 packer-plugin-hyperv_v1.1.3_x5.0_windows_amd64.exe plugin: 2024/05/09 14:41:55 [INFO] RPC endpoint: Communicator ended with: 1 2024/05/09 14:41:55 [INFO] 3047 bytes written for 'stdout' 2024/05/09 14:41:55 [INFO] 0 bytes written for 'stderr' 2024/05/09 14:41:55 [INFO] RPC client: Communicator ended with: 1 2024/05/09 14:41:55 [INFO] RPC endpoint: Communicator ended with: 1 2024/05/09 14:41:55 packer-plugin-windows-update_v0.15.0_x5.0_windows_amd64.exe plugin: 2024/05/09 14:41:55 [INFO] 0 bytes written for 'stderr' 2024/05/09 14:41:55 packer-plugin-windows-update_v0.15.0_x5.0_windows_amd64.exe plugin: 2024/05/09 14:41:55 [INFO] 3047 bytes written for 'stdout' 2024/05/09 14:41:55 packer-plugin-windows-update_v0.15.0_x5.0_windows_amd64.exe plugin: 2024/05/09 14:41:55 [INFO] RPC client: Communicator ended with: 1 2024/05/09 14:41:55 packer-plugin-windows-update_v0.15.0_x5.0_windowsamd64.exe plugin: 2024/05/09 14:41:55 Retryable error: Windows update script exited with non-zero exit status: 1

As its "retryable" - it repeats this 4 more times, until : retry count exhausted. Last err: Windows update script exited with non-zero exit status then the packer process exits and server build is removed.

I've tried various things with repeating calls to the provisioner, and the max_retries setting. When I manually restart the server while this is happening, it seems to break out of the deadlock and the packer process continues. But that is not realistic when building a stack of new servers.

Any suggestions about how to get over this issue? Looking back over Open issues, feels like this error has been a problem for a while.....will it be fixed?

Many thanks!

B-MacD22 commented 1 month ago

Been having the same issue. Looking for solutions.

rvishalturaga commented 1 week ago

Hi, I am facing a similar issue as well but for a Windows Server 2019 Datacenter VM. We are using Azure Image Builder and running the WindowsUpdate customizer. The packer-windows-update-elevated.ps1 script runs initially and then gives a non zero error. I observed a non zero exit code (101) after which the VM restarts. After the VM is back the same script is run after which I get the following error

PACKER 2024/07/18 13:43:29 ui error: ==> azure-arm: The argument 'C:/Windows/Temp/packer-windows-update-elevated.ps1' to the -File parameter does not exist. Provide the path to an existing '.ps1' file as an argument to the -File parameter. [83dbfb93-12a1-413f-a601-e186228f

Raeykall commented 6 days ago

Hi all, just to report I am seeing the same issue when attempting to use the Packer for Win11 Multi-Session

[5c307259-2810-456f-9b21-df1c667950ba] PACKER 2024/07/29 09:55:38 ui: azure-arm: ERROR: at , C:\Windows\Temp\packer-windows-update.ps1: line 190 [5c307259-2810-456f-9b21-df1c667950ba] PACKER 2024/07/29 09:55:38 ui: azure-arm: ERROR: at , : line 1 [5c307259-2810-456f-9b21-df1c667950ba] PACKER 2024/07/29 09:55:38 ui: azure-arm: ERROR EXCEPTION: System.Management.Automation.RuntimeException: You cannot call a method on a null-valued expression.

rvishalturaga commented 6 days ago

Hi @Raeykall, Can you please share in detail on what the error code is? Maybe paste a bigger section of the customizations log? Maybe we can work together to understand the issue and resolve it.

My expertise is based on Azure Image Builder only so I'm not sure to what level I can help but I want to contribute to how much ever I can. :)

jonildoasantos commented 5 days ago

Hi, I have a similar issue with Windows 11 Enterprise Multi-Session using Image Builder...

[8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:02 ui: ==> azure-arm: Running Windows update... [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:02 packer-plugin-azure plugin: 2024/07/31 02:41:02 [INFO] starting remote command: PowerShell -ExecutionPolicy Bypass -OutputFormat Text -File C:/Windows/Temp/packer-windows-update-elevated.ps1 [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:09 ui: azure-arm: Searching for Windows updates... [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:34 packer-plugin-azure plugin: 2024/07/31 02:41:34 [INFO] command 'PowerShell -ExecutionPolicy Bypass -OutputFormat Text -File C:/Windows/Temp/packer-windows-update-elevated.ps1' exited with code: 1 [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:34 packer-plugin-azure plugin: 2024/07/31 02:41:34 [INFO] RPC endpoint: Communicator ended with: 1 [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:34 [INFO] 0 bytes written for 'stderr' [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:34 [INFO] 1100 bytes written for 'stdout' [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:34 [INFO] RPC client: Communicator ended with: 1 [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:34 [INFO] RPC endpoint: Communicator ended with: 1 [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:34 ui: azure-arm: ERROR: You cannot call a method on a null-valued expression. [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:34 packer-plugin-windows-update plugin: 2024/07/31 02:41:34 [INFO] 1100 bytes written for 'stdout' [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:34 packer-plugin-windows-update plugin: 2024/07/31 02:41:34 [INFO] 0 bytes written for 'stderr' [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:34 packer-plugin-windows-update plugin: 2024/07/31 02:41:34 [INFO] RPC client: Communicator ended with: 1 [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:34 ui: azure-arm: ERROR: at , C:\Windows\Temp\packer-windows-update.ps1: line 190 [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:34 ui: azure-arm: ERROR: at , : line 1 [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:34 ui: azure-arm: ERROR EXCEPTION: System.Management.Automation.RuntimeException: You cannot call a method on a null-valued expression. [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:34 ui: azure-arm: ERROR EXCEPTION: at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception) [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:34 ui: azure-arm: ERROR EXCEPTION: at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame) [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:34 ui: azure-arm: ERROR EXCEPTION: at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:34 ui: azure-arm: ERROR EXCEPTION: at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:34 ui: azure-arm: ERROR EXCEPTION: at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:34 ui: azure-arm: ERROR EXCEPTION: at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:34 packer-plugin-windows-update plugin: 2024/07/31 02:41:34 Retryable error: Windows update script exited with non-zero exit status: 1 [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:39 packer-plugin-azure plugin: 2024/07/31 02:41:39 [INFO] starting remote command: PowerShell -ExecutionPolicy Bypass -OutputFormat Text -File C:/Windows/Temp/packer-windows-update-elevated.ps1 [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:45 ui: azure-arm: Searching for Windows updates... [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:50 [INFO] 0 bytes written for 'stderr' [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:50 packer-plugin-azure plugin: 2024/07/31 02:41:50 [INFO] command 'PowerShell -ExecutionPolicy Bypass -OutputFormat Text -File C:/Windows/Temp/packer-windows-update-elevated.ps1' exited with code: 1 [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:50 packer-plugin-azure plugin: 2024/07/31 02:41:50 [INFO] RPC endpoint: Communicator ended with: 1 [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:50 [INFO] 1100 bytes written for 'stdout' [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:50 [INFO] RPC client: Communicator ended with: 1 [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:50 ui: azure-arm: ERROR: You cannot call a method on a null-valued expression. [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:50 [INFO] RPC endpoint: Communicator ended with: 1 [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:50 packer-plugin-windows-update plugin: 2024/07/31 02:41:50 [INFO] 1100 bytes written for 'stdout' [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:50 packer-plugin-windows-update plugin: 2024/07/31 02:41:50 [INFO] 0 bytes written for 'stderr' [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:50 packer-plugin-windows-update plugin: 2024/07/31 02:41:50 [INFO] RPC client: Communicator ended with: 1 [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:50 ui: azure-arm: ERROR: at , C:\Windows\Temp\packer-windows-update.ps1: line 190 [8a6c2380-c4f9-480c-a69a-9d0bd11f2f17] PACKER 2024/07/31 02:41:50 ui: azure-arm: ERROR: at , : line 1