I want to build an image in Azure on Windows 2019 with a large file. The file contains the artifacts I need to create my image. All was going well getting the VM going until I tried to copy a 200MB file to the host. That was slated to take 11 hours. That's when I found out about WinRM and its file copy limitations.
I then found out about the http_directory parameter to copy a file to the host over http, but that is not available with the azure-arm builder.
I then saw that I can use SSH. The issue is I cannot start with the ssh provisioner and switch to the WinRM provisioner to run my ps1 configuration script. I read I can start with ssh, take an image and then start it up with WinRM. Not ideal.
I came across this software: "https://github.com/winfsp/sshfs-win" - but I am unaware of a way for a provisioned host to directly access the packer host it was provisioned by.
I came across winrmcp but that seems old and not likely to work if I could ever figure out how to get it going.
I am leaning towards blob storage, but that seems like a cop-out.
What is the best way to start a Windows 2019 Server, copy a 200MB file to it and run a ps1 script?
You can try to copy your file using Ansible provisioner. It is much faster. When I was copying a 10MB file, file provisioner took around 4 minutes but Ansible provisioner only 15 seconds.
Packer file:
source "azure-arm" "example" {
use_azure_cli_auth = true
os_type = "Windows"
communicator = "winrm"
image_offer = "WindowsServer"
image_publisher = "MicrosoftWindowsServer"
image_sku = "2016-Datacenter"
managed_image_name = "image"
managed_image_resource_group_name = "rg"
location = "westeurope"
vm_size = "Standard_D2_v2"
winrm_insecure = true
winrm_timeout = "5m"
winrm_use_ssl = true
winrm_username = "packer"
}
build {
sources = ["sources.azure-arm.example"]
provisioner "ansible" {
playbook_file = "./copy.yml"
extra_arguments = [
"-e", "ansible_winrm_server_cert_validation=ignore",
"-e", "ansible_winrm_transport=ntlm"
]
user = "packer"
use_proxy = false
}
}
Ansible playbook - copy.yml:
---
- name: Copy file to Windows host
hosts: all
tasks:
- name: Copy file
win_copy:
src: ./10MB.bin
dest: C:\10MB.bin