hashicorp / packer

Packer is a tool for creating identical machine images for multiple platforms from a single source configuration.
http://www.packer.io
Other
15.06k stars 3.32k forks source link

Error uploading the Windows update elevated script #11359

Open martijnheijden opened 2 years ago

martijnheijden commented 2 years ago

Overview of the Issue

We have running a CICD pipeline build running with the following strange issue. We are trying to build a Windows 10 Enterprise image for deployments, When we trigger the build it gets continiously into an "Upload script" error; Build 'vsphere-iso.clt-win' errored after 1 hour 33 minutes: Error uploading the Windows update elevated script: Error uploading file to $env:TEMP\winrmcp-010026fd-581f-4b86-70c3-98a6e31d2e0f.tmp: Couldn't create

Packer version 1.7.7

packer { required_plugins { windows-update = { version = ">= 0.14.0" source = "github.com/rgl/windows-update" } } }

source "vsphere-iso" "clt-win" { vcenter_server = var.vcenter_server username = var.vsphere_username password = var.vsphere_password insecure_connection = "true"

vm_name = var.vm_name cluster = var.vsphere_cluster datacenter = "NL001" datastore = var.vsphere_datastore folder = var.vsphere_folder

guest_os_type = "windows9_64Guest"

boot_order = "disk,cdrom" boot_command = [""] boot_wait = "5m"

communicator = "winrm" winrm_username = "administrator" winrm_password = var.winrm_admin_password winrm_timeout = "10m"

CPUs = 2 RAM = 8192

network_adapters { network = var.vsphere_network network_card = "vmxnet3" } storage { disk_size = 25480 disk_thin_provisioned = true } disk_controller_type = ["lsilogic-sas"] usb_controller = ["xhci"]

floppy_files = [ "/data/source/packer/preseed/Autounattend.xml", "/data/source/packer/preseed/Sysprep_Unattend.xml", "/data/source/packer/scripts/Set-NetworkProfile.ps1", "/data/source/packer/scripts/Disable-WinRM.ps1", "/data/source/packer/scripts/Enable-WinRM.ps1", "/data/source/packer/scripts/Install-Chocolatey.ps1", "/data/source/packer/scripts/Install-VMwareTools.ps1" ] iso_url = local.iso_authenticatedurl iso_checksum = var.iso_checksum iso_paths = [ "[datastore_lun.001] 01-ISO/VMware-tools-windows-11.3.5-18557794.iso" ]

shutdown_command = "C:\Windows\System32\Sysprep\sysprep.exe /generalize /oobe /unattend:A:\Sysprep_Unattend.xml /quiet /shutdown" shutdown_timeout = "1h" }

build { sources = ["source.vsphere-iso.clt-win"]

provisioner "shell-local" { inline = [ "yamllint --version", "packer --version", "pwsh --version", "ovftool --version" ] }

provisioner "powershell" { environment_vars = [ "RELEASE_VERSION=${var.vm_releaseversion}" ] scripts = [ "/data/source/packer/scripts/ReleaseInfo.ps1" ] }

provisioner "windows-update" { }

provisioner "powershell" { inline = [ "& A:\Install-Chocolatey.ps1 -repoUsername '${var.rt_username}' -repoPassword '${var.rt_password}'" ] }

provisioner "powershell" { inline = [ "choco config set --name='limit-output' --value='LimitOutput'", "choco source add --name=Artifactory --source=https://our-company-name.com/artifactory/api/nuget/nuget-public --priority=10 --user=${var.rt_username} --password=${var.rt_password}", "choco install -y dotnet3.5", "choco install -y dotnet4.7", "choco install -y 7zip.install", "choco install -y notepadplusplus.install", "choco install -y ultravnc", "choco install -y putty.install", "choco install -y powershell-core", "choco install -y foxitreader --version=11.0.1.49938 --ia '/MERGETASKS=\"!desktopicon,!setdefaultreader,!displayinbrowser /COMPONENTS=pdfviewer,ffse,installprint,ffaddin,*ffspellcheck,!connectedpdf\"'", "choco install -y pester --version=4.10.1", "choco install -y sysinternals" ] valid_exit_codes = [0, 3010] }

provisioner "windows-update" { }

provisioner "powershell" { environment_vars = [ "RT_USERNAME=${var.rt_username}", "RT_PASSWORD=${var.rt_password}" ] scripts = [ "/data/source/packer/scripts/Enable RDP.ps1", "/data/source/packer/scripts/Disabled services.ps1", "/data/source/packer/scripts/Disable IPv6.ps1", "/data/source/packer/scripts/Power settings timeout.ps1", "/data/source/packer/scripts/Corporate Identity.ps1", "/data/source/packer/scripts/bginfo.ps1", "/data/source/packer/scripts/TaskbarEliminator.ps1", "/data/source/packer/scripts/Microsoft-Edge.ps1", "/data/source/packer/scripts/WAD_Agent.ps1", "/data/source/packer/scripts/UWF_Configurator.ps1", "/data/source/packer/scripts/Startup Script.ps1", "/data/source/packer/scripts/SoftwareExpress.ps1", "/data/source/packer/scripts/CIS-Cat Assessor.ps1", "/data/source/packer/scripts/Copy Desktop Icons.ps1", "/data/source/packer/scripts/OSLocalization.ps1", "/data/source/packer/scripts/Set-VIPermissions.ps1"] }

provisioner "powershell" { inline = [ "New-Item -Path 'C:\VI\Scripts\FirstBoot' -ItemType 'Directory' -Force:$True -Confirm:$False", "New-Item -Path 'C:\VI\Scripts\GPO' -ItemType 'Directory' -Force:$True -Confirm:$False", "New-Item -Path 'C:\VI\Applications' -ItemType 'Directory' -Force:$True -Confirm:$False" ] }

provisioner "file" { destination = "C:\VI\Scripts\FirstBoot\" source = "/data/source/packer/scripts/payload/" }

provisioner "file" { destination = "C:\VI\Scripts\GPO\" source = "/data/source/packer/scripts/GPO/" }

provisioner "powershell" { scripts = [ "/data/source/packer/scripts/Register-ScheduledTask.ps1" ] } }

Log Fragments and crash.log files

`

27-Oct-2021 10:30:35 | vsphere-iso.clt-win: Installing the following packages: -- | -- 27-Oct-2021 10:30:35 | vsphere-iso.clt-win: foxitreader 27-Oct-2021 10:30:35 | vsphere-iso.clt-win: By installing, you accept licenses for the packages. 27-Oct-2021 10:30:38 | vsphere-iso.clt-win: Progress: Downloading foxitreader 11.0.1.49938... 100% 27-Oct-2021 10:30:38 | vsphere-iso.clt-win: 27-Oct-2021 10:30:38 | vsphere-iso.clt-win: foxitreader v11.0.1.49938 27-Oct-2021 10:30:38 | vsphere-iso.clt-win: foxitreader package files install completed. Performing other installation steps. 27-Oct-2021 10:31:05 | vsphere-iso.clt-win: Downloading foxitreader 27-Oct-2021 10:31:05 | vsphere-iso.clt-win:   from 'https://www.foxit.com/downloads/latest.html?product=Foxit-Reader&platform=Windows&package_type=exe&language=German&version=11.0.1.49938' 27-Oct-2021 10:48:32 | vsphere-iso.clt-win: Progress: 39% - Saving 71.25 MB of 181.6 MB 27-Oct-2021 10:49:42 | ==> vsphere-iso.clt-win: Uploading the Windows update elevated script... 27-Oct-2021 10:55:00 | ==> vsphere-iso.clt-win: Provisioning step had errors: Running the cleanup provisioner, if present... 27-Oct-2021 10:55:00 | ==> vsphere-iso.clt-win: Power off VM... 27-Oct-2021 10:55:04 | ==> vsphere-iso.clt-win: Deleting Floppy image ... 27-Oct-2021 10:55:08 | ==> vsphere-iso.clt-win: Destroying VM... 27-Oct-2021 10:55:09 | Build 'vsphere-iso.clt-win' errored after 1 hour 33 minutes: Error uploading the Windows update elevated script: Error uploading file to $env:TEMP\winrmcp-010026fd-581f-4b86-70c3-98a6e31d2e0f.tmp: Couldn't create shell: unknown error Post "http://xx.xx.xx.xx:5985/wsman": dial tcp xx.xx.xx.xx:5985: i/o timeout 27-Oct-2021 10:55:09 |   27-Oct-2021 10:55:09 | ==> Wait completed after 1 hour 33 minutes 27-Oct-2021 10:55:09 |   27-Oct-2021 10:55:09 | ==> Some builds didn't complete successfully and had errors: 27-Oct-2021 10:55:09 | --> vsphere-iso.clt-win: Error uploading the Windows update elevated script: Error uploading file to $env:TEMP\winrmcp-010026fd-581f-4b86-70c3-98a6e31d2e0f.tmp: Couldn't create shell: unknown error Post "http://xx.xx.xx.xx:5985/wsman": dial tcp xx.xx.xx.xx:5985: i/o timeout 27-Oct-2021 10:55:09 |   27-Oct-2021 10:55:09 | ==> Builds finished but no artifacts were created. 27-Oct-2021 10:55:10 | Failing task since return code of [/bin/sh /home/bamboo/bamboo-agent-home/temp/IT-VIITCLTWINNEW95-JOB5-30-ScriptBuildTask-7576411886203981301.sh] was 1 while expected 0 27-Oct-2021 10:55:10 | Finished task 'Script' with result: Failed

`

djpbessems commented 2 years ago

Colleague of OP here:

It's worth mentioning, that the issue pops up on basically any random point in time during this build: Somehow, the current running provisioner disappears (no progress can be seen anymore within packer's debug logging), and packer decides to start the next provisioner, which will fail with the Error uploading file to $env:TEMP\winrmcp-<uuid>.tmp: Couldn't create shell error.

We tried disabling different provisioners, tried disabling installation of different chocolatey packages, tried reordering provisioners, tried adding reboots in between provisioners (and in between chocolatey installations).

We tried updating Packer to different versions, we tried updating VMware Tools, we tried using a different Windows 10 iso.