Alternative to WinRM file provisioner

I’ve had the pleasure of experiencing the woefully slow file transfer problem with WinRM. It is suggested in the documentation to use SSH or some sort of HTTP transfer. Has anyone got a slick - not too complicated - method of getting files transferred?

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 = [""]

  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

    - name: Copy file
        src: ./10MB.bin
        dest: C:\10MB.bin
1 Like

This does work, but it’s missing a bunch of other information to get it going. Check out this post on GitHub; Ansible Provisioner Missing Pywinrm Dependency in venv ("winrm or requests is not installed: No module named 'winrm'") · Issue #11217 · hashicorp/packer · GitHub