Open AshTechieDevOps opened 1 year ago
Even no other command gets executed by shutdown_command during packer build.
I was creating and deploying images using PackerBuild@1. I was also stuck once a couple of months back with the same issue, however, I was following standard packer build procedure i.e. creating a JSON file for packer having builder and provisioners.
Initially what I was doing is after my provisioner typed "PowerShell" execution i was executing the Sysprep command as you have written. When I included the "windows restart" type in packer JSON before executing the Sysprep cmd, it worked. I checked it by logging into the VM created to modify the Sysprep server needs restarts. That's where I included this block.
{ "type": "windows-restart", "restart_check_command": "powershell -command \"& {Write-Output 'Restarted.'}\"" }
I'm relatively new in Packer, so I thought to share with you guys my experience and workaround. Hope you get some idea from this article.
Hi @AshTechieDevOps, pretty sure the issue is a non-successful sysprep
process. Please double check the file C:\Windows\System32\Sysprep\Panther\*.log
and look for Errors. Alternatively you can use the error-cleanup-provisioner
which will allow you to grab the logfiles before the machine is being killed by packer.
See below:
error-cleanup-provisioner "powershell" {
inline = [
"Get-ChildItem -Path 'C:/Windows/System32/Sysprep/Panther' -Filter '*.log' | Get-Content",
]
# elevated_user = "<your-username>"
# elevated_password = "<your-password>"
}
this is most likely not a packer bug, so I'd recommend we close it here.
Packer stuck at: "Gracefully halting virtual machine" and (shutdown_command = "%windir%\system32\sysprep\sysprep.exe /unattend:A:\Autounattend.xml /quiet /generalize /oobe /shutdown /mode:VM") never gets executed then finally packer build gets failed without creating build arctifacts stating timed out issue post "shutdown_timeout"+"winrm_timeout".
I am using latest version of Packer and Hyper-V as my hypervisor and I am successfully above to manully execute "%windir%\system32\sysprep\sysprep.exe /quiet /generalize /oobe /shutdown /mode:VM" but having issue with (shutdown_command = "%windir%\system32\sysprep\sysprep.exe /unattend:A:\Autounattend.xml /quiet /generalize /oobe /shutdown /mode:VM"). Any suggestions.
packer { required_plugins { hyperv = { version = ">= 1.1.0" source = "github.com/hashicorp/hyperv" } } }
source "hyperv-iso" "autogenerated_1" { iso_checksum = "sha256:6DAE072E7F78F4CCAB74A45341DE0D6E2D45C39BE25F1F5920A2AB4F51D7BCBB" iso_url = "C:/AshImages/2019/17763.3650.221105-1748.rs5_release_svc_refresh_SERVER_EVAL_x64FRE_en-us.iso" output_directory = "C:/CSG/2k19PackerBuild" skip_export = true use_fixed_vhd_format = true vm_name = "windows2019-vhd-packer" communicator = "none" skip_compaction = true winrm_timeout = "5m" shutdown_timeout = "25m" shutdown_command = "%windir%\system32\sysprep\sysprep.exe /unattend:A:\Autounattend.xml /quiet /generalize /oobe /shutdown /mode:VM"
floppy_files = [ "C:/CSG-DC/Autounattend.xml" ]
boot_command = [ "",
"",
"D:\setup.exe /unattend:A:\Autounattend.xml",
"",
]
}
build { sources = ["hyperv-iso.autogenerated_1"] }