title: azure-arm Windows VM provisioning with Ansible
body: <p>Is it possible to use Packer on a Mac to create a Windows VM on azure-arm with Ansible as provisioner? I am looking for a working example.</p>
  
  <p><a href="https://www.packer.io/docs/provisioners/ansible.html#winrm-communicator" rel="nofollow noreferrer">Packer documentation</a> mentions that winrm communicator needs a <a href="https://github.com/hashicorp/packer/tree/master/examples/ansible/connection-plugin" rel="nofollow noreferrer">connection_plugin for Packer</a>, but it has not been updated since Ansible 2.6.</p>
  
  <p><code>ansible_playbook.sh</code> runs ansible-playbook using these libraries with python 3.6</p>
  
  <ul>
  <li>pywinrm[kerberos]==0.2.2 </li>
  <li>ansible[azure]</li>
  </ul>
  
  <pre><code>    #!/bin/bash
      source /usr/local/miniconda3/etc/profile.d/conda.sh &amp;&amp; conda activate ${CONDA_ENV} &amp;&amp; ANSIBLE_FORCE_COLOR=1 PYTHONUNBUFFERED=1 /usr/local/miniconda3/envs/py36_64/bin/ansible-playbook "$@"
  </code></pre>
  
  <p>My ansible-playbook packer.yml is simple:</p>
  
  <pre><code>    ---
      - name: setup new Azure box
        hosts: default
        gather_facts: no
  
        vars_files:
          - dependencies.yml
  
        roles:
          - {role: ansible-windows-java, tags: java}
          - {role: itigoag.chrome, tags: chrome}
  </code></pre>
  
  <p>My packer.json for Azure looks like this:</p>
  
  <pre><code>{
    "builders": [
      {
        "client_id": "{{user `arm_client_id`}}",
        "client_secret": "{{user `arm_client_secret`}}",
        "communicator": "winrm",
        "image_offer": "VisualStudio",
        "image_publisher": "MicrosoftVisualStudio",
        "image_sku": "VS-2017-Comm-Latest-WS2016",
        "image_version": "latest",
        "location": "{{user `arm_location`}}",
        "managed_image_name": "windows2016-vsc",
        "managed_image_resource_group_name": "{{user `arm_resource_group`}}",
        "os_type": "Windows",
        "subscription_id": "{{user `arm_subscription_id`}}",
        "tenant_id": "{{user `arm_tenant_id`}}",
        "type": "azure-arm",
        "winrm_insecure": "true",
        "winrm_timeout": "3m",
        "winrm_use_ssl": "true",
        "winrm_username": "packer",
        "vm_size": "Standard_D8_v3"
      }
    ],
    "provisioners": [
      {
        "command": "/usr/local/bin/ansible_playbook.sh",
        "extra_arguments": [
          "--connection", "packer",
          "--extra-vars", "ansible_shell_type=powershell ansible_shell_executable=None"
        ],
        "playbook_file": "packer.yml",
        "type": "ansible"
      }
    ],
    "variables": {
      "arm_client_id": "{{env `ARM_CLIENT_ID`}}",
      "arm_client_secret": "{{env `ARM_CLIENT_SECRET`}}",
      "arm_location": "{{env `ARM_LOCATION`}}",
      "arm_resource_group": "{{env `ARM_RESOURCE_GROUP`}}",
      "arm_storage_account": "{{env `ARM_STORAGE_ACCOUNT`}}",
      "arm_subscription_id": "{{env `ARM_SUBSCRIPTION_ID`}}",
      "arm_tenant_id": "{{env `ARM_TENNANT_ID`}}"
    }
  }
  </code></pre>
  
  <p>A VM is created, but the process stops after a while with the following errors in the log, pointing to use of <code>ssh</code>, but <code>winrm</code> is mentioned too! Unclear how this is supposed to work.</p>
  
  <pre><code>==&gt; azure-arm: Waiting for WinRM to become available...
  ==&gt; azure-arm: #&lt; CLIXML
      azure-arm: WinRM connected.
  ==&gt; azure-arm: &lt;Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"&gt;&lt;Obj S="progress" RefId="0"&gt;&lt;TN RefId="0"&gt;&lt;T&gt;System.Management.Automation.PSCustomObject&lt;/T&gt;&lt;T&gt;System.Object&lt;/T&gt;&lt;/TN&gt;&lt;MS&gt;&lt;I64 N="SourceId"&gt;1&lt;/I64&gt;&lt;PR N="Record"&gt;&lt;AV&gt;Preparing modules for first use.&lt;/AV&gt;&lt;AI&gt;0&lt;/AI&gt;&lt;Nil /&gt;&lt;PI&gt;-1&lt;/PI&gt;&lt;PC&gt;-1&lt;/PC&gt;&lt;T&gt;Completed&lt;/T&gt;&lt;SR&gt;-1&lt;/SR&gt;&lt;SD&gt; &lt;/SD&gt;&lt;/PR&gt;&lt;/MS&gt;&lt;/Obj&gt;&lt;Obj S="progress" RefId="1"&gt;&lt;TNRef RefId="0" /&gt;&lt;MS&gt;&lt;I64 N="SourceId"&gt;1&lt;/I64&gt;&lt;PR N="Record"&gt;&lt;AV&gt;Preparing modules for first use.&lt;/AV&gt;&lt;AI&gt;0&lt;/AI&gt;&lt;Nil /&gt;&lt;PI&gt;-1&lt;/PI&gt;&lt;PC&gt;-1&lt;/PC&gt;&lt;T&gt;Completed&lt;/T&gt;&lt;SR&gt;-1&lt;/SR&gt;&lt;SD&gt; &lt;/SD&gt;&lt;/PR&gt;&lt;/MS&gt;&lt;/Obj&gt;&lt;/Objs&gt;
  ==&gt; azure-arm: Connected to WinRM!
  ==&gt; azure-arm: Provisioning with Ansible...
  ==&gt; azure-arm: Executing Ansible: /usr/local/bin/ansible_playbook.sh --extra-vars packer_build_name=azure-arm packer_builder_type=azure-arm -o IdentitiesOnly=yes -i /var/folders/hs/b03p_c310l70v6zx1byb4l0r0000gp/T/packer-provisioner-ansible072959676 /Users/bas/code/vd/azure-win2016/packer.yml -e ansible_ssh_private_key_file=/var/folders/hs/b03p_c310l70v6zx1byb4l0r0000gp/T/ansible-key860669585 --connection packer --extra-vars ansible_shell_type=powershell ansible_shell_executable=None
      azure-arm:
      azure-arm: PLAY [setup new Azure box] *****************************************************
      azure-arm:
      azure-arm: TASK [ansible-windows-java : Install Java] *************************************
      azure-arm: Saturday 29 June 2019  20:58:35 +0200 (0:00:00.155)       0:00:00.155 *********
      azure-arm: fatal: [default]: FAILED! =&gt; changed=false
      azure-arm:   module_stderr: |-
      azure-arm:     Warning: Permanently added '[127.0.0.1]:54679' (RSA) to the list of known hosts.
      azure-arm:     Parameter format not correct - ;
      azure-arm:   module_stdout: ''
      azure-arm:   msg: |-
      azure-arm:     MODULE FAILURE
      azure-arm:     See stdout/stderr for the exact error
      azure-arm:   rc: 1
      azure-arm:
      azure-arm: PLAY RECAP *********************************************************************
      azure-arm: default                    : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0
      azure-arm:
      azure-arm: Saturday 29 June 2019  20:58:36 +0200 (0:00:00.726)       0:00:00.881 *********
      azure-arm: ===============================================================================
      azure-arm: ansible-windows-java : Install Java ------------------------------------- 0.73s
      azure-arm: Playbook run took 0 days, 0 hours, 0 minutes, 0 seconds
  ==&gt; azure-arm:
  ==&gt; azure-arm: Cleanup requested, deleting resource group ...
  </code></pre>