rgl / packer-plugin-windows-update

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

Packer Exiting Before Updates are Installed #90

Open tomloveland1 opened 3 years ago

tomloveland1 commented 3 years ago

I can see that windows update is finding the updates, but before it gets a chance to finish downloading (or installing) the updates, packer finishes up and closes the build.

I've attached an example from Server 2012 R2, but I've observed the same behavior in Windows Server 2016 and Windows Server 2019.

Build File { "builders": [ { "CPUs": "{{ vmCpuNum }}", "RAM": "{{ vmMemSize }}", "CPU_hot_plug": "true", "RAM_hot_plug": "true",
"cluster": "{{ vsphereCluster }}", "communicator": "winrm", "datacenter": "{{ vsphereDatacenter }}", "datastore": "{{ vsphereDatastore }}", "disk_controller_type": "pvscsi", "firmware": "bios", "floppy_files": [ "autounattend.xml", "ConfigureVM.ps1" ], "folder": "{{ vsphereFolder }}", "guest_os_type": "windows9Server64Guest", "insecure_connection": "true", "iso_paths": [ "{{ osIsoPath }}", "[] /vmimages/tools-isoimages/windows.iso" ], "network_adapters": [ { "network": "{{ vsphereNetwork }}", "network_card": "vmxnet3" } ], "password": "{{ ansible_password }}", "storage": [ { "disk_size": "{{ vmDiskSize }}" } ], "type": "vsphere-iso", "username": "{{ ansible_user }}", "vcenter_server": "{{ vsphereServer }}", "vm_name": "{{ vmName }}", "winrm_password": "{{ winAdminPassword }}", "winrm_username": "Administrator" } ], "provisioners": [ { "filters": [ "include:$true" ], "search_criteria": "BrowseOnly=0 and IsInstalled=0", "type": "windows-update", "update_limit": 1000, "max_retries": 5 } ] }

Results ok: [v01utlwin702.allianceqa.lan] => {} MSG: vsphere-iso: output will be in this color. ==> vsphere-iso: Creating VM... ==> vsphere-iso: Customizing hardware... ==> vsphere-iso: Mounting ISO images... ==> vsphere-iso: Adding configuration parameters... ==> vsphere-iso: Creating floppy disk... vsphere-iso: Copying files flatly from floppy_files vsphere-iso: Copying file: autounattend.xml vsphere-iso: Copying file: ConfigureVM.ps1 vsphere-iso: Done copying files from floppy_files vsphere-iso: Collecting paths from floppy_dirs vsphere-iso: Resulting paths from floppy_dirs : [] vsphere-iso: Done copying paths from floppy_dirs ==> vsphere-iso: Uploading created floppy image ==> vsphere-iso: Adding generated Floppy... ==> vsphere-iso: Set boot order temporary... ==> vsphere-iso: Power on VM... ==> vsphere-iso: Waiting for IP... ==> vsphere-iso: IP address: 10.17.109.37 ==> vsphere-iso: Using winrm communicator to connect: 10.17.109.37 ==> vsphere-iso: Waiting for WinRM to become available... vsphere-iso: WinRM connected. ==> vsphere-iso: Connected to WinRM! ==> vsphere-iso: Uploading the Windows update elevated script... ==> vsphere-iso: Uploading the Windows update check for reboot required elevated script... ==> vsphere-iso: Uploading the Windows update script... ==> vsphere-iso: Running Windows update... vsphere-iso: Searching for Windows updates... vsphere-iso: Waiting for operation to complete (system performance: 10 % cpu; 7 % memory)... vsphere-iso: Waiting for operation to complete (system performance: 16 % cpu; 8 % memory)... vsphere-iso: Waiting for operation to complete (system performance: 15 % cpu; 8 % memory)... vsphere-iso: Found Windows update (2014-05-13; 0.1 MB): Update for .NET Native on Windows 8.1 and Windows Server 2012 R2 for x64-based Systems (KB2954879) vsphere-iso: Found Windows update (2014-07-08; 10.96 MB): Update for Windows Server 2012 R2 (KB2938066) vsphere-iso: Found Windows update (2014-07-08; 4.1 MB): Security Update for Windows Server 2012 R2 (KB2973201) vsphere-iso: Found Windows update (2014-08-12; 3.37 MB): Security Update for Windows Server 2012 R2 (KB2976897) vsphere-iso: Found Windows update (2014-08-12; 21.44 MB): Update for Windows Server 2012 R2 (KB2967917) vsphere-iso: Found Windows update (2014-09-09; 6.57 MB): Security Update for Microsoft .NET Framework 4.5.1 on Windows 8.1 and Windows Server 2012 R2 for x64-based Systems (KB2894856) vsphere-iso: Found Windows update (2014-09-09; 13.21 MB): Security Update for Microsoft .NET Framework 4.5.1 and 4.5.2 on Windows 8.1 and Windows Server 2012 R2 x64-based Systems (KB2977765) vsphere-iso: Found Windows update (2014-10-14; 2.4 MB): Security Update for Microsoft .NET Framework 4.5.1 and 4.5.2 on Windows 8.1 and Windows Server 2012 R2 x64-based Systems (KB2978041) vsphere-iso: Found Windows update (2014-11-11; 0.57 MB): Security Update for Microsoft .NET Framework 4.5.1 and 4.5.2 on Windows 8.1 and Windows Server 2012 R2 x64-based Systems (KB2978126) vsphere-iso: Found Windows update (2014-11-11; 0.08 MB): Security Update for Windows Server 2012 R2 (KB3010788) vsphere-iso: Found Windows update (2014-12-09; 0.22 MB): Update for Windows Server 2012 R2 (KB3008242) vsphere-iso: Found Windows update (2014-12-09; 0.16 MB): Update for Windows Server 2012 R2 (KB2989930) vsphere-iso: Found Windows update (2014-12-09; 1.08 MB): Update for Windows Server 2012 R2 (KB3013410) vsphere-iso: Found Windows update (2015-01-13; 0.06 MB): Security Update for Windows Server 2012 R2 (KB3023266) vsphere-iso: Found Windows update (2015-01-13; 0.06 MB): Security Update for Windows Server 2012 R2 (KB3019978) vsphere-iso: Found Windows update (2015-03-10; 14.78 MB): Update for Windows Server 2012 R2 (KB3012702) vsphere-iso: Found Windows update (2015-03-10; 0.09 MB): Update for Windows Server 2012 R2 (KB3013172) vsphere-iso: Found Windows update (2015-03-10; 0.64 MB): Update for Windows Server 2012 R2 (KB3024751) vsphere-iso: Found Windows update (2015-03-10; 0.54 MB): Update for Windows Server 2012 R2 (KB3024755) vsphere-iso: Found Windows update (2015-03-10; 2.12 MB): Update for Windows Server 2012 R2 (KB3027209) vsphere-iso: Found Windows update (2015-03-10; 3.87 MB): Update for Windows Server 2012 R2 (KB3030947) vsphere-iso: Found Windows update (2015-03-10; 0.7 MB): Update for Windows Server 2012 R2 (KB3036612) vsphere-iso: Found Windows update (2015-04-07; 890.18 MB): Windows Server 2012 R2 Update (KB2919355) vsphere-iso: Found Windows update (2015-04-14; 0.3 MB): Update for Windows Server 2012 R2 (KB3042085) vsphere-iso: Found Windows update (2015-04-14; 775.22 MB): Update for Windows Server 2012 R2 (KB3000850) vsphere-iso: Found Windows update (2015-04-14; 5.68 MB): Security Update for Windows Server 2012 R2 (KB3045999) vsphere-iso: Found Windows update (2015-04-14; 0.25 MB): Security Update for Windows Server 2012 R2 (KB3045685) vsphere-iso: Found Windows update (2015-04-14; 6.83 MB): Security Update for Microsoft .NET Framework 4.5.1 and 4.5.2 on Windows 8.1 and Windows Server 2012 R2 x64-based Systems (KB3037579) vsphere-iso: Found Windows update (2015-05-12; 1.49 MB): Update for Windows Server 2012 R2 (KB3043812) vsphere-iso: Found Windows update (2015-05-12; 0.25 MB): Update for Windows Server 2012 R2 (KB3044673) vsphere-iso: Found Windows update (2015-05-12; 2.96 MB): Update for Windows Server 2012 R2 (KB3054169) vsphere-iso: Found Windows update (2015-05-12; 1.2 MB): Update for Windows Server 2012 R2 (KB3048043) vsphere-iso: Found Windows update (2015-05-12; 1.25 MB): Update for Windows Server 2012 R2 (KB3045717) vsphere-iso: Found Windows update (2015-05-12; 0.16 MB): Update for Windows Server 2012 R2 (KB3033446) vsphere-iso: Found Windows update (2015-05-12; 0.16 MB): Update for Windows Server 2012 R2 (KB3038002) vsphere-iso: Found Windows update (2015-05-12; 0.13 MB): Update for Windows Server 2012 R2 (KB3045719) vsphere-iso: Found Windows update (2015-05-12; 0.13 MB): Update for Windows Server 2012 R2 (KB3046737) vsphere-iso: Found Windows update (2015-05-12; 3.56 MB): Update for Windows Server 2012 R2 (KB3013538) vsphere-iso: Found Windows update (2015-05-12; 0.54 MB): Security Update for Microsoft .NET Framework 4.5.1 and 4.5.2 on Windows 8.1 and Windows Server 2012 R2 x64-based Systems (KB3032663) vsphere-iso: Found Windows update (2015-05-12; 4.31 MB): Security Update for Microsoft .NET Framework 4.5.1 and 4.5.2 on Windows 8.1 and Windows Server 2012 R2 x64-based Systems (KB3023222) vsphere-iso: Found Windows update (2015-06-09; 0.16 MB): Update for Windows Server 2012 R2 (KB3055323) vsphere-iso: Found Windows update (2015-06-09; 0.78 MB): Update for Windows Server 2012 R2 (KB3054464) vsphere-iso: Found Windows update (2015-06-09; 0.25 MB): Update for Windows Server 2012 R2 (KB3045634) vsphere-iso: Found Windows update (2015-06-09; 2.65 MB): Security Update for Windows Server 2012 R2 (KB3059317) vsphere-iso: Found Windows update (2015-07-14; 0.19 MB): Update for Windows Server 2012 R2 (KB3013791) vsphere-iso: Found Windows update (2015-07-14; 0.07 MB): Update for Windows Server 2012 R2 (KB3060793) vsphere-iso: Found Windows update (2015-07-14; 0.25 MB): Update for Windows Server 2012 R2 (KB3063843) vsphere-iso: Found Windows update (2015-07-14; 1.44 MB): Update for Windows Server 2012 R2 (KB3054256) vsphere-iso: Found Windows update (2015-07-14; 0.04 MB): Update for Windows Server 2012 R2 (KB3054203) vsphere-iso: Found Windows update (2015-07-14; 0.15 MB): Update for Windows Server 2012 R2 (KB3060681) vsphere-iso: Found Windows update (2015-07-14; 0.04 MB): Security Update for Windows Server 2012 R2 (KB3061512) vsphere-iso: Found Windows update (2015-08-11; 8.21 MB): Update for Windows Server 2012 R2 (KB3071663) vsphere-iso: Found Windows update (2015-08-11; 3.5 MB): Update for Windows Server 2012 R2 (KB3044374) vsphere-iso: Found Windows update (2015-08-11; 0.26 MB): Security Update for Windows Server 2012 R2 (KB3046017) vsphere-iso: Found Windows update (2015-08-11; 5.41 MB): Security Update for Windows Server 2012 R2 (KB3071756) vsphere-iso: Found Windows update (2015-09-08; 2.99 MB): Security Update for Windows Server 2012 R2 (KB3082089) vsphere-iso: Found Windows update (2015-09-08; 0.78 MB): Security Update for Windows Server 2012 R2 (KB3084135) vsphere-iso: Found Windows update (2015-09-08; 0.74 MB): Security Update for Microsoft .NET Framework 4.5.1 and 4.5.2 on Windows 8.1 and Windows Server 2012 R2 x64-based Systems (KB3074228) vsphere-iso: Found Windows update (2015-09-08; 1.08 MB): Security Update for Microsoft .NET Framework 4.5.1 and 4.5.2 on Windows 8.1 and Windows Server 2012 R2 x64-based Systems (KB3074548) vsphere-iso: Found Windows update (2015-09-08; 1.04 MB): Update for Windows Server 2012 R2 (KB3080149) vsphere-iso: Found Windows update (2015-09-08; 0.61 MB): Update for Windows Server 2012 R2 (KB3077715) vsphere-iso: Found Windows update (2015-09-08; 0.04 MB): Security Update for Windows Server 2012 R2 (KB3086255) vsphere-iso: Found Windows update (2015-10-13; 2.17 MB): Update for Windows Server 2012 R2 (KB3087137) vsphere-iso: Found Windows update (2015-11-10; 0.07 MB): Update for Windows Server 2012 R2 (KB3094486) vsphere-iso: Found Windows update (2015-11-10; 0.19 MB): Update for Windows Server 2012 R2 (KB3091297) vsphere-iso: Found Windows update (2015-11-10; 0.1 MB): Update for Windows Server 2012 R2 (KB3078405) vsphere-iso: Found Windows update (2015-11-10; 3.91 MB): Security Update for Windows Server 2012 R2 (KB3081320) vsphere-iso: Found Windows update (2015-11-10; 1.68 MB): Security Update for Windows Server 2012 R2 (KB3102939) vsphere-iso: Found Windows update (2015-11-10; 0.31 MB): Security Update for Windows Server 2012 R2 (KB3092601) vsphere-iso: Found Windows update (2015-11-10; 6.84 MB): Security Update for Microsoft .NET Framework 4.5.1 and 4.5.2 on Windows 8.1 and Windows Server 2012 R2 x64-based Systems (KB3098779) vsphere-iso: Found Windows update (2015-11-13; 1.16 MB): Security Update for Microsoft .NET Framework 4.5.1 and 4.5.2 for Windows 8.1 for x64-based Systems (KB3097997) vsphere-iso: Found Windows update (2015-12-08; 0.11 MB): Security Update for Windows Server 2012 R2 (KB3109103) vsphere-iso: Found Windows update (2015-12-08; 0.08 MB): Update for Windows Server 2012 R2 (KB3099834) vsphere-iso: Found Windows update (2015-12-08; 0.61 MB): Update for Windows Server 2012 R2 (KB3103696) vsphere-iso: Found Windows update (2016-01-12; 16.4 MB): Security Update for Windows Server 2012 R2 (KB3110329) vsphere-iso: Found Windows update (2016-02-09; 8.39 MB): Security Update for Windows Server 2012 R2 (KB3126593) vsphere-iso: Found Windows update (2016-02-09; 0.23 MB): Security Update for Windows Server 2012 R2 (KB3133043) vsphere-iso: Found Windows update (2016-02-09; 0.76 MB): Security Update for Windows Server 2012 R2 (KB3126041) vsphere-iso: Found Windows update (2016-02-09; 0.47 MB): Security Update for Windows Server 2012 R2 (KB3126434) vsphere-iso: Found Windows update (2016-02-09; 1.17 MB): Security Update for Windows Server 2012 R2 (KB3126587) vsphere-iso: Found Windows update (2016-02-09; 4.26 MB): Update for Windows Server 2012 R2 (KB3132080) vsphere-iso: Found Windows update (2016-03-08; 0.14 MB): Security Update for Windows Server 2012 R2 (KB3139398) vsphere-iso: Found Windows update (2016-03-08; 0.04 MB): Security Update for Windows Server 2012 R2 (KB3139914) vsphere-iso: Found Windows update (2016-03-08; 6.82 MB): Update for Windows Server 2012 R2 (KB3121261) vsphere-iso: Found Windows update (2016-03-08; 0.19 MB): Update for Windows Server 2012 R2 (KB3134815) vsphere-iso: Found Windows update (2016-04-12; 12.12 MB): Security Update for Windows Server 2012 R2 (KB3146723) vsphere-iso: Found Windows update (2016-04-12; 13.14 MB): Update for Windows Server 2012 R2 (KB3147071) vsphere-iso: Found Windows update (2016-04-12; 30.1 MB): Update for Windows Server 2012 R2 (KB3138602) vsphere-iso: Found Windows update (2016-04-12; 1.1 MB): Update for Windows Server 2012 R2 (KB3137728) vsphere-iso: Found Windows update (2016-04-12; 0.07 MB): Update for Windows Server 2012 R2 (KB3140219) vsphere-iso: Found Windows update (2016-04-12; 2.41 MB): Update for Windows Server 2012 R2 (KB3109976) vsphere-iso: Found Windows update (2016-04-12; 13.08 MB): Update for Windows Server 2012 R2 (KB3115224) vsphere-iso: Found Windows update (2016-04-12; 0.09 MB): Update for Windows Server 2012 R2 (KB3133690) vsphere-iso: Found Windows update (2016-04-12; 0.08 MB): Update for Windows Server 2012 R2 (KB3140234) vsphere-iso: Found Windows update (2016-04-12; 1.81 MB): Update for Windows Server 2012 R2 (KB3100473) vsphere-iso: Found Windows update (2016-04-12; 2.35 MB): Update for Windows Server 2012 R2 (KB3123245) vsphere-iso: Found Windows update (2016-05-10; 0.77 MB): Update for Windows Server 2012 R2 (KB3146604) vsphere-iso: Found Windows update (2016-05-10; 0.18 MB): Update for Windows Server 2012 R2 (KB3103616) vsphere-iso: Found Windows update (2016-05-10; 0.16 MB): Update for Windows Server 2012 R2 (KB3146751) vsphere-iso: Found Windows update (2016-05-10; 0.17 MB): Update for Windows Server 2012 R2 (KB3145384) vsphere-iso: Found Windows update (2016-05-10; 2.48 MB): Update for Windows Server 2012 R2 (KB3149157) vsphere-iso: Found Windows update (2016-05-10; 0.27 MB): Update for Windows Server 2012 R2 (KB3145432) vsphere-iso: Found Windows update (2016-05-10; 1.47 MB): Update for Windows Server 2012 R2 (KB3103709) vsphere-iso: Found Windows update (2016-05-10; 1.31 MB): Update for Windows Server 2012 R2 (KB3134179) vsphere-iso: Found Windows update (2016-05-10; 0.28 MB): Security Update for Windows Server 2012 R2 (KB3156059) vsphere-iso: Found Windows update (2016-06-14; 1.41 MB): Security Update for Windows Server 2012 R2 (KB3159398) vsphere-iso: Found Windows update (2016-06-14; 1.32 MB): Security Update for Windows Server 2012 R2 (KB3161949) vsphere-iso: Found Windows update (2016-08-09; 10.32 MB): Security Update for Windows Server 2012 R2 (KB3172729) vsphere-iso: Found Windows update (2016-09-13; 12.1 MB): Security Update for Windows Server 2012 R2 (KB3175024) vsphere-iso: Found Windows update (2016-09-13; 0.35 MB): Security Update for Windows Server 2012 R2 (KB3178539) vsphere-iso: Found Windows update (2016-09-13; 28.51 MB): Update for Windows Server 2012 R2 (KB3179574) vsphere-iso: Found Windows update (2017-08-08; 3.5 MB): Update for Windows Server 2012 R2 (KB4033428) vsphere-iso: Found Windows update (2017-12-12; 296.02 MB): 2017-12 Security Monthly Quality Rollup for Windows Server 2012 R2 for x64-based Systems (KB4054519) vsphere-iso: Found Windows update (2020-01-14; 70.48 MB): Microsoft .NET Framework 4.8 for Windows Server 2012 R2 for x64 (KB4486105) vsphere-iso: Found Windows update (2021-01-14; 0.07 MB): VMware, Inc. - Net - 1.8.17.0 vsphere-iso: Warning The update 'VMware, Inc. - Display - 8.17.2.14' has the CanRequestUserInput flag set (if the install hangs, you might need to exclude it with the filter 'exclude:$.InstallationBehavior.CanRequestUserInput' or 'exclude:$.Title -like 'VMware, Inc. - Display - 8.17.2.14'') vsphere-iso: Found Windows update (2021-03-12; 17.1 MB): VMware, Inc. - Display - 8.17.2.14 vsphere-iso: Found Windows update (2021-04-13; 10.28 MB): 2021-04 Servicing Stack Update for Windows Server 2012 R2 for x64-based Systems (KB5001403) vsphere-iso: Found Windows update (2021-04-13; 539.21 MB): 2021-04 Security Monthly Quality Rollup for Windows Server 2012 R2 for x64-based Systems (KB5001382) vsphere-iso: Found Windows update (2021-04-13; 33.18 MB): Windows Malicious Software Removal Tool x64 - v5.88 (KB890830) vsphere-iso: Downloading Windows updates (119 updates; 2975.8 MB)... ==> vsphere-iso: Shutting down VM... ==> vsphere-iso: Deleting Floppy drives... ==> vsphere-iso: Deleting Floppy image... ==> vsphere-iso: Eject CD-ROM drives... ==> vsphere-iso: Clear boot order... Build 'vsphere-iso' finished after 15 minutes 32 seconds. ==> Wait completed after 15 minutes 32 seconds ==> Builds finished. The artifacts of successful builds are: --> vsphere-iso: Windows 2012 R2 Standard-01-WIP

rgl commented 3 years ago

You've found a known corner case where this breaks. Sometimes, Windows seems to drop all the current WinRM (or Windows Update) connections, and this is not correctly handled by this provisioner.

For updating windows 2012 try doing it like https://github.com/rgl/windows-vagrant/blob/master/windows-2012-r2.pkr.hcl#L181-L188

If it still does not work, adding extra calls to the windows-update provisioner might help. That is, instead of calling it once, call it multiple times.

tomloveland1 commented 3 years ago

That’s really helpful information, thank you. I’ve been grinding on this issues for over a month. Simply calling the same provisioner multiple times solved the problem. Thanks for the work you do.

Thanks,

Tom Loveland

From: Rui Lopes @.> Sent: Thursday, April 15, 2021 1:00 PM To: rgl/packer-provisioner-windows-update @.> Cc: Thomas Loveland @.>; Author @.> Subject: Re: [rgl/packer-provisioner-windows-update] Packer Exiting Before Updates are Installed (#90)

CAUTION: This email is from outside of the organization. DO NOT CLICK a link or open an attachment unless you know the content is safe and are expecting it from the sender.

You've found a known corner case where this breaks. Sometimes, Windows seems to drop all the current WinRM (or Windows Update) connections, and this is not correctly handled by this provisioner.

For updating windows 2012 try doing it like https://github.com/rgl/windows-vagrant/blob/master/windows-2012-r2.pkr.hcl#L181-L188https://urldefense.com/v3/__https:/github.com/rgl/windows-vagrant/blob/master/windows-2012-r2.pkr.hcl*L181-L188__;Iw!!PUAtEBz4obiNUzU!aMESbn8U1K7zodxfHCex5127xeRNmkkY7uvgGcWNkDzUYa1sXFgcMLx_4wDdVfmUnXF6XKiE20Hy$

If it still does not work, adding extra calls to the windows-update provisioner might help. That is, instead of calling it once, call it multiple times.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://urldefense.com/v3/__https:/github.com/rgl/packer-provisioner-windows-update/issues/90*issuecomment-820623364__;Iw!!PUAtEBz4obiNUzU!aMESbn8U1K7zodxfHCex5127xeRNmkkY7uvgGcWNkDzUYa1sXFgcMLx_4wDdVfmUnXF6XOdhRIKg$, or unsubscribehttps://urldefense.com/v3/__https:/github.com/notifications/unsubscribe-auth/AHON6XFDOFR6WQ5JUKIFTGDTI4SRVANCNFSM42755FIQ__;!!PUAtEBz4obiNUzU!aMESbn8U1K7zodxfHCex5127xeRNmkkY7uvgGcWNkDzUYa1sXFgcMLx_4wDdVfmUnXF6XB_n2O7A$.

novaliswolf commented 3 years ago

@rgl thank you for this, I'm also having the same problem. Just wanted to clarify when you say 'call it multiple times' do you mean instead of:

provisioner "windows-update" { }

do the following?

 provisioner "windows-update" {  }

 provisioner "windows-update" {  }

 provisioner "windows-update" {  }
rgl commented 3 years ago

Yes. Maybe with some pause before each (all provisioners support the pause_before property). e.g. provisioner "windows-update" { pause_before = "1m" }

novaliswolf commented 3 years ago

Thank you it seems to be working now, although it's random hopefully that's fixed it, appreciate the help

frippe75 commented 2 years ago

I used the max_retries provisioners option instead of calling windows-update provisioner plugin multiple times in a row. But it does not help. I'm using OpenSSH instead of WinRM and my packer-windows-update-evelvated.ps1 always exits with a 1.

Looking at the console Windows Update is clearly running installing a large cumulative KB. It finnishes in the end. But the windows-update plugin seems to have lost its perception of whats going on.

Once ready a restart i pending. Would be ok if windows-update ran until that stage and then exited with a 0 and gave me the opertunity to do a restart separately.

lovetheguitar commented 2 years ago

I used the max_retries provisioners option instead of calling windows-update provisioner plugin multiple times in a row. But it does not help. I'm using OpenSSH instead of WinRM and my packer-windows-update-evelvated.ps1 always exits with a 1.

Looking at the console Windows Update is clearly running installing a large cumulative KB. It finnishes in the end. But the windows-update plugin seems to have lost its perception of whats going on.

Once ready a restart i pending. Would be ok if windows-update ran until that stage and then exited with a 0 and gave me the opertunity to do a restart separately.

I have exactly the same problem, it installs the updates and fails with exit code 1 afterwards. During the first run it usually fails like this:

vsphere-iso.base_win: Waiting for operation to complete (system performance: 8 % cpu; 49 % memory)...
    vsphere-iso.base_win: Waiting for operation to complete (system performance: 7 % cpu; 50 % memory)...
    vsphere-iso.base_win: Waiting for operation to complete (system performance: 6 % cpu; 49 % memory)...
    vsphere-iso.base_win: Waiting for operation to complete (system performance: 13 % cpu; 50 % memory)...
==> vsphere-iso.base_win: retry count exhausted. Last err: dial tcp 192.168.8.22:22: i/o timeout
==> vsphere-iso.base_win: Step "StepProvision" failed

Could that be a power plan setting? That windows goes to sleep meanwhile? Here the output of the second try:

vsphere-iso.base_win: Uploading the Windows update elevated script...
==> vsphere-iso.base_win: Uploading the Windows update check for reboot required elevated script...
==> vsphere-iso.base_win: Uploading the Windows update script...
==> vsphere-iso.base_win: Running Windows update...
    vsphere-iso.base_win: Waiting for the Windows Modules Installer to exit...
    vsphere-iso.base_win: Waiting for the Windows Modules Installer to exit...
    vsphere-iso.base_win: Waiting for the Windows Modules Installer to exit...
    vsphere-iso.base_win: Waiting for the Windows Modules Installer to exit...
    vsphere-iso.base_win: Waiting for the Windows Modules Installer to exit...
==> vsphere-iso.base_win: retry count exhausted. Last err: Windows update script exited with non-zero exit status: 1
==> vsphere-iso.base_win: Step "StepProvision" failed
==> vsphere-iso.base_win: [c] Clean up and exit, [a] abort without cleanup, or [r] retry step (build may fail even if retry succeeds)?

This happens like this again and again until I manually restart the machine, then it succeeds.

I tried to find a reference to some environment variables in the update scripts, but could not find anything meaningful. Might first suspicion was that this current openssh limitation could be the reason for the failures.

A workaround for me at the moment is to use the ansible.windows.win_updates module. In first tests it appears to work.