rgl / packer-plugin-windows-update

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

Windows update script exited with non-zero exit status: 259 #22

Open spaceygithub opened 6 years ago

spaceygithub commented 6 years ago

First time using this provider but keep hitting a problem during everybuild. Any suggestions please? Can see it also disscussed here but I've tried adding a reboot before and after the windows update provisioner. https://github.com/rgl/packer-provisioner-windows-update/issues/3

Snipet from my build json file

Everything before this works fine. { "type": "windows-restart" }, { "type": "windows-update", "filters": [ "exclude:$.Title -like 'Preview'", "include:$.Title -like 'Cumulative Update for Windows'", "include:$.Title -like 'Recommended'", "include:$.AutoSelectOnWebSites" ] }, { "type": "windows-restart" }, { "type": "powershell", "inline": [ "C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts\InitializeDisks.ps1 -Schedule", "C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts\InitializeInstance.ps1 -Schedule", "C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts\SysprepInstance.ps1 -noshutdown" ] } ]

20:35:11 ==> amazon-ebs: Uploading the Windows update elevated script... 20:35:14 ==> amazon-ebs: Uploading the Windows update script... 20:35:16 ==> amazon-ebs: Running Windows update... 20:35:18 amazon-ebs: #< CLIXML 20:35:18 amazon-ebs: Pending Reboot detected. Waiting for the Windows Modules Installer to exit... 20:35:33 amazon-ebs: Rebooting... 20:35:33 amazon-ebs: System.Management.Automation.PSCustomObjectSystem.Object1Preparing modules for first use.0-1-1Completed-1 2Preparing modules for first use.0-1-1Completed-1 20:35:33 ==> amazon-ebs: Waiting for machine to restart... 20:35:33 amazon-ebs: A system shutdown is in progress.(1115) 20:36:30 amazon-ebs: EC2AMAZ-8TNC0L4 restarted. 20:36:30 amazon-ebs: #< CLIXML 20:36:30 amazon-ebs: System.Management.Automation.PSCustomObjectSystem.Object1Preparing modules for first use.0-1-1Completed-1 20:36:30 ==> amazon-ebs: Machine successfully restarted, moving on 20:36:30 ==> amazon-ebs: Running Windows update... 20:36:33 amazon-ebs: #< CLIXML 20:36:34 amazon-ebs: Searching for Windows updates... 20:37:04 amazon-ebs: Found Windows update (2018-09-20; 1348.38 MB): 2018-09 Cumulative Update for Windows Server 2016 for x64-based Systems (KB4457127) 20:37:04 amazon-ebs: Found Windows update (2018-10-05; 74.93 MB): Definition Update for Windows Defender Antivirus - KB2267602 (Definition 1.277.663.0) 20:37:04 amazon-ebs: Downloading Windows updates... 20:37:49 amazon-ebs: Installing Windows updates... 21:19:34 amazon-ebs: Pending Reboot detected. Waiting for the Windows Modules Installer to exit... 21:21:45 amazon-ebs: Rebooting... 21:21:45 amazon-ebs: System.Management.Automation.PSCustomObjectSystem.Object1Preparing modules for first use.0-1-1Completed-1 2Preparing modules for first use.0-1-1Completed-1 21:21:45 ==> amazon-ebs: Waiting for machine to restart... 21:21:45 amazon-ebs: A system shutdown is in progress.(1115) 21:23:23 amazon-ebs: EC2AMAZ-8TNC0L4 restarted. 21:23:23 amazon-ebs: #< CLIXML 21:23:23 amazon-ebs: System.Management.Automation.PSCustomObjectSystem.Object1Preparing modules for first use.0-1-1Completed-1 21:23:23 ==> amazon-ebs: Machine successfully restarted, moving on 21:23:23 ==> amazon-ebs: Running Windows update... 21:23:26 amazon-ebs: #< CLIXML 21:23:29 amazon-ebs: Searching for Windows updates... 21:28:23 ==> amazon-ebs: Terminating the source AWS instance... 21:30:10 ==> amazon-ebs: Cleaning up any extra volumes... 21:30:10 ==> amazon-ebs: No volumes to clean up, skipping 21:30:10 ==> amazon-ebs: Deleting temporary security group... 21:30:11 ==> amazon-ebs: Deleting temporary keypair... 21:30:11 Build 'amazon-ebs' errored: Windows update script exited with non-zero exit status: 259 21:30:11 21:30:11 ==> Some builds didn't complete successfully and had errors: 21:30:11 --> amazon-ebs: Windows update script exited with non-zero exit status: 259 21:30:11 21:30:11 ==> Builds finished but no artifacts were created.

rgl commented 6 years ago

There is something strange going on while detecting if the machine completed the reboot (while the updates are installing the machine sometimes restarts multiple times and this provider is not detecting that). You could try with packer 1.2.5 (the restart provider stopped working after this version, but seems to be fixed in the unreleased 1.3.2) and change the winrm service startup to delayed-auto to see if that helps.

rgl commented 6 years ago

Can you please try again with 0.6.0 and packer 1.2.5?

rgl commented 6 years ago

Also do not set any options on the provision step, i.e. use:

{
    "provisioners": [
        {
            "type": "windows-update"
        }
    ]
}
spaceygithub commented 6 years ago

Thanks for all the advice and apologies for the delay in getting back to you. Illness and then holiday got in the way.

Version 1.2.5 was working without error for about the last 7 build runs but has started to fail with the same error code. I found packer 1.3.2_dev on https://github.com/hashicorp/packer/issues/6733 and tried that. While I don’t get the intermittent exit (1115) errors on 1.3.2 I'm still getting exit 259 on every attempted run.

I’ve noted your recommendation to remove the filters and just have the windows update line. So, just trying that and will let you know the outcome.

To ensure I'm not the cause here is my provisioners prior to changing the filters.

  "provisioners": [
      {
        "type": "file",
        "direction": "upload",
        "source": "ec2Launch/DriveLetterMappingConfig.json",
        "destination": "C:\\ProgramData\\Amazon\\EC2-Windows\\Launch\\Config\\DriveLetterMappingConfig.json"
      },
      {
        "type": "powershell",
        "inline": [
          "C:\\ProgramData\\Amazon\\EC2-Windows\\Launch\\Scripts\\InitializeDisks.ps1"
        ]
      },
      {
        "type": "file",
        "direction": "upload",
        "source": "sysprep/Unattend.xml",
        "destination": "C:\\ProgramData\\Amazon\\EC2-Windows\\Launch\\Sysprep\\Unattend.xml"
      },
      {
        "type": "powershell",
        "scripts": "provisioning_scripts/configure_base_os.ps1"
      },
      {
        "type": "file",
        "direction": "download",
        "source": "C:\\Temp\\PackerBuild\\Configure_base_os.txt",
        "destination": "logs/Configure_base_os_{{timestamp}}.txt"
      },
      {
        "type": "powershell",
        "scripts": "provisioning_scripts/install_chocolatey.ps1"
      },
      {
        "type": "powershell",
        "valid_exit_codes": [0, 3010],
        "scripts": "provisioning_scripts/install_packages.ps1"
      },
      {
        "type": "powershell",
        "scripts": "provisioning_scripts/install_aws_codedeploy_agent.ps1"
      },
      {
        "type": "windows-restart"
      },
      {
        "type": "windows-update",
        "filters": [
                "exclude:$_.Title -like '*Preview*'",
                "include:$_.Title -like '*Cumulative Update for Windows*'",
                "include:$_.Title -like '*Recommended*'",
                "include:$_.AutoSelectOnWebSites"
            ]
      },
      {
        "type": "windows-restart"
      },
      {
        "type": "powershell",
        "inline": [
          "C:\\ProgramData\\Amazon\\EC2-Windows\\Launch\\Scripts\\InitializeDisks.ps1 -Schedule",
          "C:\\ProgramData\\Amazon\\EC2-Windows\\Launch\\Scripts\\InitializeInstance.ps1 -Schedule",
          "C:\\ProgramData\\Amazon\\EC2-Windows\\Launch\\Scripts\\SysprepInstance.ps1 -noshutdown"
        ]
      }
    ],

Which produces build errors like this:

Snipped to save space
10:10:56     amazon-ebs: Running
10:10:56 ==> amazon-ebs: Restarting Machine
10:10:56 ==> amazon-ebs: Waiting for machine to restart...
10:10:57     amazon-ebs: A system shutdown is in progress.(1115)
10:11:08     amazon-ebs: A system shutdown is in progress.(1115)
10:12:09     amazon-ebs: EC2AMAZ-8PJDHTV restarted.
10:12:09     amazon-ebs: #< CLIXML
10:12:09     amazon-ebs: <Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><Obj S="progress" RefId="0"><TN RefId="0"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj></Objs>
10:12:09 ==> amazon-ebs: Machine successfully restarted, moving on
10:12:09 ==> amazon-ebs: Uploading the Windows update elevated script...
10:12:24 ==> amazon-ebs: Uploading the Windows update script...
10:12:36 ==> amazon-ebs: Running Windows update...
10:12:49     amazon-ebs: #< CLIXML
10:12:51     amazon-ebs: Searching for Windows updates...
10:13:21     amazon-ebs: Found Windows update (2018-10-18; 1350.96 MB): 2018-10 Cumulative Update for Windows Server 2016 for x64-based Systems (KB4462928)
10:13:21     amazon-ebs: Found Windows update (2018-10-26; 51.6 MB): Definition Update for Windows Defender Antivirus - KB2267602 (Definition 1.279.549.0)
10:13:21     amazon-ebs: Downloading Windows updates...
10:14:05     amazon-ebs: Installing Windows updates...
10:56:00     amazon-ebs: Pending Reboot detected. Waiting for the Windows Modules Installer to exit...
10:57:39     amazon-ebs: Rebooting...
10:57:39     amazon-ebs: <Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><Obj S="progress" RefId="0"><TN RefId="0"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj><Obj S="progress" RefId="1"><TNRef RefId="0" /><MS><I64 N="SourceId">2</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj></Objs>
10:57:39 ==> amazon-ebs: Waiting for machine to restart...
10:57:40     amazon-ebs: A system shutdown is in progress.(1115)
10:58:45     amazon-ebs: EC2AMAZ-8PJDHTV restarted.
10:58:45     amazon-ebs: #< CLIXML
10:58:45     amazon-ebs: <Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><Obj S="progress" RefId="0"><TN RefId="0"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj></Objs>
10:58:45 ==> amazon-ebs: Machine successfully restarted, moving on
10:58:45 ==> amazon-ebs: Running Windows update...
10:58:58     amazon-ebs: #< CLIXML
10:59:04     amazon-ebs: Searching for Windows updates...
11:03:57 ==> amazon-ebs: Terminating the source AWS instance...
11:05:43 ==> amazon-ebs: Cleaning up any extra volumes...
11:05:43 ==> amazon-ebs: No volumes to clean up, skipping
11:05:43 ==> amazon-ebs: Deleting temporary security group...
11:05:44 ==> amazon-ebs: Deleting temporary keypair...
11:05:44 Build 'amazon-ebs' errored: Windows update script exited with non-zero exit status: 259
11:05:44 
11:05:44 ==> Some builds didn't complete successfully and had errors:
11:05:44 --> amazon-ebs: Windows update script exited with non-zero exit status: 259
11:05:44 
11:05:44 ==> Builds finished but no artifacts were created.
spaceygithub commented 6 years ago

Can confirm that updating to 0.6 and using 1.3.2_dev has allowed for my build to complete for the first time today. I'll schedule more builds over the next 24 hours to confirm if the intermittentness of the fault has also gone. Thanks again for the help.

ccoager commented 5 years ago

Having the same issue on Windows Server 2016 using Packer v1.3.4 with windows-update v0.6.1. It's been 24 hours and windows-update is hung on "Waiting for the Windows Modules Installer to exit". Code appears to be waiting on TiWorker.exe to exit even though all updates completed installation. Eventually it failed exactly 24 hours later with "RPC endpoint: Communicator ended with: 259". I was able to reproduce this multiple times.

2019/01/30 09:47:30 packer: 2019/01/30 09:47:30 [INFO] starting remote command: PowerShell -ExecutionPolicy Bypass -OutputFormat Text -File C:/Windows/Temp/packer-windows-update-elevated.ps1 amazon-ebs: Searching for Windows updates... amazon-ebs: Found Windows update (2018-11-13; 11.43 MB): 2018-11 Update for Windows Server 2016 for x64-based Systems (KB4465659) amazon-ebs: Found Windows update (2019-01-08; 1.07 MB): 2018-10 Update for Windows Server 2016 for x64-based Systems (KB4091664) amazon-ebs: Found Windows update (2019-01-17; 1383.22 MB): 2019-01 Cumulative Update for Windows Server 2016 for x64-based Systems (KB4480977) amazon-ebs: Downloading Windows updates (3 updates; 1395.72 MB)... amazon-ebs: Installing Windows updates... amazon-ebs: Waiting for the Windows Modules Installer to exit... 2019/01/31 09:47:36 packer: 2019/01/31 09:47:36 [INFO] command 'PowerShell -ExecutionPolicy Bypass -OutputFormat Text -File C:/Windows/Temp/packer-windows-update-elevated.ps1' exited with code: 259 2019/01/31 09:47:36 [INFO] 544 bytes written for 'stdout' 2019/01/31 09:47:36 packer: 2019/01/31 09:47:36 [INFO] RPC endpoint: Communicator ended with: 259 2019/01/31 09:47:36 [INFO] 0 bytes written for 'stderr' 2019/01/31 09:47:36 [INFO] RPC client: Communicator ended with: 259 2019/01/31 09:47:36 [INFO] RPC endpoint: Communicator ended with: 259 2019/01/31 09:47:36 packer-provisioner-windows-update: 2019/01/31 09:47:36 [INFO] 544 bytes written for 'stdout' 2019/01/31 09:47:36 packer-provisioner-windows-update: 2019/01/31 09:47:36 [INFO] 0 bytes written for 'stderr' 2019/01/31 09:47:36 packer-provisioner-windows-update: 2019/01/31 09:47:36 [INFO] RPC client: Communicator ended with: 259 2019/01/31 09:47:36 [INFO] (telemetry) ending windows-update ==> amazon-ebs: Terminating the source AWS instance... ==> amazon-ebs: Cleaning up any extra volumes... ==> amazon-ebs: No volumes to clean up, skipping ==> amazon-ebs: Deleting temporary keypair... 2019/01/31 09:50:39 [INFO] (telemetry) ending amazon-ebs 2019/01/31 09:50:39 ui error: Build 'amazon-ebs' errored: Windows update script exited with non-zero exit status: 259 2019/01/31 09:50:39 Builds completed. Waiting on interrupt barrier... 2019/01/31 09:50:39 machine readable: error-count []string{"1"} 2019/01/31 09:50:39 ui error: ==> Some builds didn't complete successfully and had errors: 2019/01/31 09:50:39 machine readable: amazon-ebs,error []string{"Windows update script exited with non-zero exit status: 259"} 2019/01/31 09:50:39 ui error: --> amazon-ebs: Windows update script exited with non-zero exit status: 259 ==> Builds finished but no artifacts were created. Build 'amazon-ebs' errored: Windows update script exited with non-zero exit status: 259

2019/01/31 09:50:39 [INFO] (telemetry) Finalizing. ==> Some builds didn't complete successfully and had errors: --> amazon-ebs: Windows update script exited with non-zero exit status: 259

rgl commented 3 years ago

Please try v0.14.0 and let us known how it goes.