Ansible - Azure resource referencing My aim is to have my vnet and subnet in a seperate resource group from the other parts of my infrastructure i.e Virtual Machines.
I have a short playbook that creates the resource group for my network (vnet &amp; subnet), which works fine. I can build a VM via the portal and all is well.
My other playbook creates a resource group, creates a vmnic and VM. This playbook references the vnet and subnet created in the other resource group.
I'm encountering an error (see below) when referencing the resources in the network resource group I created. I found a previous post that has helped by suggesting the use of the &quot;set_fact&quot; module.
I've tried different ways of entering set_fact key values (full resource path / part resource path), but I keep getting an error. I suspect it maybe due to interpolation? Note the double &quot;//&quot; in the error message.
Could anyone provide some guidance on where I'm going wrong, please?
Error message:

fatal: [localhost]: FAILED! =&gt; {&quot;changed&quot;: false, &quot;msg&quot;: &quot;Error creating or updating network interface test-vm-vnic1 - Azure Error: InvalidRequestFormat\nMessage: Cannot parse the request.\nException Details:\n\tError Code: InvalidJsonReferenceFormat\n\tMessage: Reference Id /subscriptions/REMOVED-SUB-ID/resourceGroups/test-rg/providers/Microsoft.Network/virtualNetworks//providers/Microsoft.Network/virtualNetworks/vnet-ansible-test/subnets//subnets/snet-ansible-test is not formatted correctly. The Id is expected to reference resources of type virtualNetworks/subnets. Path properties.ipConfigurations[0].properties.subnet.&quot;}

Part of playbook:
  tasks:
   - set_fact:
       vnet_rg_id: &quot;/subscriptions/REMOVED-SUB-ID/resourceGroups/rg-ansible-test&quot;
       vnet_id: &quot;/providers/Microsoft.Network/virtualNetworks/vnet-ansible-test&quot;
       snet_id: &quot;/subnets/snet-ansible-test&quot;

   - name: Create resource group
     azure_rm_resourcegroup:
       name: &quot;{{ rg }}&quot; # this is var declared earlier in the playbook
       location: &quot;{{ location }}&quot; # this is var declared earlier in the playbook

   - name: Create virtual network inteface cards for VM
     azure_rm_networkinterface:
       resource_group: &quot;{{ rg }}&quot; # this is var declared earlier in the playbook
       name: &quot;{{ nic_name }}&quot; # this is var declared earlier in the playbook
       virtual_network: &quot;{{ vnet_id }}&quot;
       subnet: &quot;{{ snet_id }}&quot;
       location: &quot;{{ location }}&quot; # this is var declared earlier in the playbook
With a bit trial and error I was able to work out the values for my &quot;vnet_id&quot; and &quot;snet_id&quot; variables.
I found using the full ID for the virtual network and not having a &quot;/&quot; before the subnet variable (snet_id) value fixed my problem.
At the moment I don't fully understand how Ansible/Azure puts it all together, but this has given me enough information to start to understand.
If anyone could point me to some documentation that explains the construction/interpolation of the variables it would be helpful.
  tasks:
   - set_fact:
       vnet_rg_id: &quot;/subscriptions/REVMOVED-SUB-ID/resourceGroups/rg-ansible-test&quot;
       vnet_id: &quot;/subscriptions/REVMOVED-SUB-ID/resourceGroups/rg-ansible-test/providers/Microsoft.Network/virtualNetworks/vnet-ansible-test&quot;
       snet_id: &quot;snet-ansible-test&quot;

   - name: Create resource group
     azure_rm_resourcegroup:
       name: &quot;{{ rg }}&quot; # declared earlier in the playbook
       location: &quot;{{ location }}&quot; # declared earlier in the playbook

   - name: Create virtual network inteface cards for VM
     azure_rm_networkinterface:
       resource_group: &quot;{{ rg }}&quot; # declared earlier in the playbook
       name: &quot;{{ nic_name }}&quot; # declared earlier in the playbook
       virtual_network: &quot;{{ vnet_id }}&quot;
       subnet: &quot;{{ snet_id }}&quot;
       location: &quot;{{ location }}&quot; # declared earlier in the playbook