title: Update the disk storage type in azure windows vm using ansible playbook
body: <p>I have written 4 tasks for it first for power off the vm, second to verify if it is stopped, 3rd to update and then power on the vm. But the problem is even when the machine is stopped ansible is giving error &quot;Operation not allowed&quot;. You can see the error below. Please suggest me the correct way of doing it as I am new to ansible. Please also clarify which task to run on localhost and which on windows.</p>
  <p>fatal: [localhost]: FAILED! =&gt; {&quot;changed&quot;: false, &quot;msg&quot;: &quot;Error creating the managed disk: Azure Error: OperationNotAllowed\nMessage: Cannot change account type, fault domain or network spine of disk &lt;&lt;disk_name&gt;&gt; while it is attached to running VM &lt;&lt;vm_name&gt;&gt;.&quot;}</p>
  <pre><code>- name: Update Disk type
    hosts: localhost
    gather_facts: no
    tasks:
    - name: Power off the VM
      azure_rm_virtualmachine:
        resource_group: &quot;{{resource_group}}&quot;
        name: &quot;{{vm_name}}&quot;
        started: no
  
    - name: Verify that the machine is stopped
      win_ping:
      #delegate_to: localhost
      failed_when: false
      ignore_unreachable: true
      register: ping_result
  
    - debug: var=ping_result
  
    - name: Update the disk type
      azure_rm_manageddisk:
        name: &quot;{{disk_name}}&quot;
        resource_group: &quot;{{resource_group}}&quot;
        storage_account_type: &quot;{{type}}&quot;
        disk_size_gb: &quot;{{size}}&quot;
   
    - name: Power on the VM
      azure_rm_virtualmachine:
        resource_group: &quot;{{resource_group}}&quot;
        name: &quot;{{vm_name}}&quot;
  </code></pre>