I am working on creating an Ansible playbook to

  • Ensure required network resources for an Azure VM are present, and
  • Create an Azure VM attached to those resources.

Due to the way the organization is structured, all network resources (such as NIC, NSG, Subnets and Public IPs) are placed in a Networks Resource Group in Azure. And these are managed by a separate team.

Also, the mandate is to create the Azure VMs and all non network resources in a separate resource group (let's call it AZRVMRG.

The chunk of the playbook that creates the VM looks like this:

- name: "Create VM {{vm_type}} - {{name}}"
    resource_group: "{{rg_name}}"
    name: "{{name}}"
    vm_size: "{{size}}"
    admin_username: "{{user}}"
    admin_password: "{{pass}}"
    os_type: "{{os_type}}"
    network_interfaces: "{{nic_name}}"
    image: "{{image}}"
    tags: "{{tags}}"

Where {{rg_name}} is the AZRVMRG RG, and {{nic_name}} is an existing NIC present in the Networks RG.


How do I reference the NIC present in the Networks resource group while creating the Azure VM within AZRVMRG resource group?

What I've tried

I have tried "just" referencing the NIC name, but that gives me an error similar to:

 "msg": "Error fetching network interface AZRVMNIC - Azure Error: ResourceNotFound\nMessage: The Resource 'Microsoft.Network/networkInterfaces/AZRVMNIC' under resource group 'AZRVMRG' was not found."

So clearly, its looking under the same resource group.


(I have seen VMs created in the Azure subscription this way, so this is possible in Azure. But Ansible does not document this approach in its official docs. )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.