Get VM Metadata with Ansible

I needed to get VM Metadata and store it in a variable I could use later as a variable in an Ansible playbook.

  pre_tasks:
    - name: Get ResourceGroup name from metadata service
      uri:
        url: http://169.254.169.254/metadata/instance/compute/resourceGroupName?api-version=2017-08-01&format=text
        headers:
          metadata: true
        return_content: yes
      register: resourcegroup
    - debug:
        var: resourcegroup.content

I was then able to reference the resourceGroup name

configuration_variable: "{{ resourcegroup.content | lower }}"