title: Ansible - Tagging Azure running VMs
body: <p>Today I've been working in finding the best way to tag running VMs in Azure automatically from Ansible. </p>
  
  <p>The first approach was using <code>azure_rm_virtualmachine</code> module, but it works fine at the time of deploying a new VM. When the VM is up and running, that is another history, mostly when the deployment has been done with custom images.</p>
  
  <pre><code>  - name: Tag my VM
      azure_rm_virtualmachine:
        resource_group: myresourcegroup
        name: myvm
        admin_username: ansible
        admin_password: mypassword
        virtual_network_name: myvnet
        virtual_network_resource_group: myvnetrsg
        vm_size: Standard_D2_v2
        state: present
        started: no
        append_tags: True
        image:
          name: mycustomimage
          resource_group: myimagesrsg
        tags:
          env: "dev"
  </code></pre>
  
  <p>See: <a href="https://github.com/ansible/ansible/issues/35235" rel="nofollow noreferrer">https://github.com/ansible/ansible/issues/35235</a> solved in 2.7 but still not working with Custom Images.</p>
  
  <p>So the question is how doing it with running VMs? How changing old tags and adding new ones?</p>