Abesh Rajasekharan
Abesh Rajasekharan

Reputation: 11

Using Ansible how can I provision a network interface in Azure and associate it with a virtual network in another resource group?

I am trying to create a network interface in a resource group with name "net-interface" and associate it with a virtual network that belongs to resource group with name "virtual-net". I am able to do it manually, but when I use Ansible, it is expecting the virtual network to be in network interface resource group "net-interface". even tries giving the complete URI for the virtual network.

azure_rm_networkinterface:
  name: testnetworkinfrastructure
  resource_group: testsourcegroup1
  virtual_network_name: /subscriptions/xxxxxxxxxxxxxxxxxxxxx/resourceGroups/testsourcegroup1/providers/Microsoft.Network/virtualNetworks/testvirtualnetwork
  subnet_name: testsubnet
  security_group_name: testsecuritygroup
  location: West Europe
  state: present

failed: [localhost] (item=ansible20-nic-01) => {"failed": true, "item": "ansible20-nic-01", "msg": "Error: fetching subnet testsubnet in virtual network /subscriptions/xxxxxxxxxxxxxxxxxxx/resourceGroups/testsourcegroup1/providers/Microsoft.Network/virtualNetworks/testvirtualnetwork - Azure Error: ResourceNotFound\nMessage: The Resource 'Microsoft.Network/virtualNetworks/subscriptions' under resource group 'testsourcegroup1' was not found."}

Am I doing something wrong? Or is there any workaround?

Upvotes: 1

Views: 872

Answers (1)

techraf
techraf

Reputation: 68449

Unfortunately, your case seems not to be covered by the current implementation of the azure_rm_networkinterface module.

It checks for the presence of the subnet in the same resource group as the network interface and fails gracefully with the message you got:

def get_subnet(self, vnet_name, subnet_name):
    self.log("Fetching subnet {0} in virtual network {1}".format(subnet_name, vnet_name))
    try:
        subnet = self.network_client.subnets.get(self.resource_group, vnet_name, subnet_name)
    except Exception as exc:
        self.fail("Error: fetching subnet {0} in virtual network {1} - {2}".format(subnet_name, vnet_name, str(exc)))

From a brief examination, it looks like the Azure SDK for Python requires a resource group to be specified, so you can either:

  • customise the azure_rm_networkinterface module to specify the subnet resource group, or

  • create an Azure RM template deployment with azure_rm_deployment.

Upvotes: 1

Related Questions