Problems using Packer and Ansible with WinRM Connection

I added this to build in my buildspec.yml

  • echo “Building HashiCorp Packer template, win2019.json”
  • export POWERSHELL_VERSION=""
  • ./packer build win2019.json

That and I upgraded to a newer version of packer and that did it:

I was having the following error with the ansible provisioner

 [WARNING]: ERROR DURING WINRM SEND INPUT - attempting to recover:
WinRMOperationTimeoutError

I got it fixed with the following…

provisioner "ansible" {
    use_proxy = false
    user      = var.ADMIN_USER
    extra_arguments = ["-e ansible_shell_type=powershell",
      "-e ansible_shell_executable=None",
      "-e ansible_connection=winrm",
      "-e ansible_port=5986",
      "-e ansible_password=${build.WinRMPassword}",
      "-e ansible_winrm_server_cert_validation=ignore",
      "-e ansible_winrm_operation_timeout_sec=3600",
      "-e ansible_winrm_read_timeout_sec=7200",
      "-vv"
    ]
    playbook_file    = "../../ansible/playbooks/playbook.yml"
    ansible_env_vars = [                        "ANSIBLE_COLLECTION_PATHS=$HOME/.ansible/collections:/usr/share/ansible/collections"]
  }