--- - name: get resource group info become: true become_user: root # become_method: runas hosts: localhost gather_facts: no tasks: - name: Get all facts azure_rm_virtualmachine_info: register: all_facts no_log: true - name: set RG name set_fact: rg_name: "{{item.resource_group}}" when: item.name == "{{ vmname }}" with_items: "{{all_facts.vms}}" no_log: true - name: get rg_info debug: msg: "The vm {{vmname}} is located in the resource group {{rg_name}}" environment: #aperam.com - AZURE_CLIENT_ID: "{{AZURE_CLIENT_ID}}" - AZURE_SECRET: "{{AZURE_SECRET}}" - AZURE_SUBSCRIPTION_ID: "{{AZURE_SUBSCRIPTION_ID}}" - AZURE_TENANT: "{{AZURE_TENANT}}"