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 & 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 "set_fact" 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 "//" in the error message.
Could anyone provide some guidance on where I'm going wrong, please?
Error message:
fatal: [localhost]: FAILED! => {"changed": false, "msg": "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."}
Part of playbook:
tasks:
- set_fact:
vnet_rg_id: "/subscriptions/REMOVED-SUB-ID/resourceGroups/rg-ansible-test"
vnet_id: "/providers/Microsoft.Network/virtualNetworks/vnet-ansible-test"
snet_id: "/subnets/snet-ansible-test"
- name: Create resource group
azure_rm_resourcegroup:
name: "{{ rg }}" # this is var declared earlier in the playbook
location: "{{ location }}" # this is var declared earlier in the playbook
- name: Create virtual network inteface cards for VM
azure_rm_networkinterface:
resource_group: "{{ rg }}" # this is var declared earlier in the playbook
name: "{{ nic_name }}" # this is var declared earlier in the playbook
virtual_network: "{{ vnet_id }}"
subnet: "{{ snet_id }}"
location: "{{ location }}" # this is var declared earlier in the playbook