packer-plugin-azure icon indicating copy to clipboard operation
packer-plugin-azure copied to clipboard

Uploading large file and directories using SSH communicator to create Azure Windows Image

Open hc-github-team-packer opened this issue 1 year ago • 0 comments

This issue was originally opened by @Zaheerkhan999 in https://github.com/hashicorp/packer/issues/12284 and has been migrated to this repository. The original issue description is below.


Hi,

I am creating an image with file folders to be uploaded into the Azure windows image.

What I have done so far. I have created a custom windows image with SSH server installed and running the below packer script to provision a new image from that custom image. Packer is able to create all the required resources at runtime but not able to upload any files to it and terminates with the error "Context deadline exceeded". The same is achievable from winrm but failing with SSH. Since the files and directories are huge in size so it is taking a lot of time to transfer using winrm that's why I chose SSH communicator to quicky upload the files but its failing.

######################################################################## source "azure-arm" "autogenerated_1" { azure_tags = { dept = "Engineering" task = "Image deployment" } build_resource_group_name = "TEST-RG" client_id = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" client_secret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" communicator = "ssh" custom_managed_image_name = "SSH-WindowsImage" custom_managed_image_resource_group_name = "TEST-RG"
managed_image_name = "Windows-image" managed_image_resource_group_name = "TEST-RG" os_type = "Windows" subscription_id = "XXXXXXXXXXXXXXXXXXXXX" tenant_id = "XXXXXXXXXXXXXXXXXXXXX" vm_size = "Standard_D2_v2" ssh_username = "userzktest1" ssh_password = "PassPktest@123!" ssh_port = 22 pause_before_connecting = "5m" ssh_file_transfer_method = "sftp"

}

build { sources = ["source.azure-arm.autogenerated_1"]

provisioner "file" { source = "files/bin.zip" destination = "C:/code/bin.zip"

}

provisioner "powershell" { inline = ["while ((Get-Service RdAgent).Status -ne 'Running') { Start-Sleep -s 5 }", "while ((Get-Service WindowsAzureGuestAgent).Status -ne 'Running') { Start-Sleep -s 5 }", "& $env:SystemRoot\System32\Sysprep\Sysprep.exe /oobe /generalize /quiet /quit", "while($true) { $imageState = Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\State | Select ImageState; if($imageState.ImageState -ne 'IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE') { Write-Output $imageState.ImageState; Start-Sleep -s 10 } else { break } }"] }

} ###############################################################################

Any help will be highly appreciated.

Thanks in advance.

hc-github-team-packer avatar Apr 07 '23 22:04 hc-github-team-packer