# How to use existing network in a different RG in Azure with ansible

**URL:** <https://forum.ansible.com/t/how-to-use-existing-network-in-a-different-rg-in-azure-with-ansible/37588>\
**Category:** Ansible Project\
**Tags:** azure\
**Created:** [January 27, 2023, 8:46pm UTC](https://forum.ansible.com/t/how-to-use-existing-network-in-a-different-rg-in-azure-with-ansible/37588 "2023-01-27T20:46:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![williamflow](https://avatars.discourse-cdn.com/v4/letter/w/65b543/32.png) [@williamflow](https://forum.ansible.com/u/williamflow)\
**Post date:** [January 27, 2023, 8:46pm UTC](https://forum.ansible.com/t/how-to-use-existing-network-in-a-different-rg-in-azure-with-ansible/37588/1 "2023-01-27T20:46:09Z")

</div>

My goal here is to create a VM in Azure with Ansible

- name: Create a VM

azure.azcollection.azure\_rm\_virtualmachine:

resource\_group: RG-Bill

name: testvm002

vm\_size: Standard\_DS1\_v2

admin\_username: centos

ssh\_public\_keys:

- path: /home/centos/.ssh/authorized\_keys

key\_data: blah blah

virtual\_network\_resource\_group: RG-Net

virtual\_network\_name: VNET1

subnet\_name: SUBNET\_VNET1

public\_ip\_allocation: Disabled

image:

offer: CentOS

publisher: OpenLogic

sku: “7.5”

version: latest

What happens here is the PB throws the error:

“Error creating default security rule testvm00201 - (AuthorizationFailed) The client ‘xxxxxxxxxxx’ with object id ‘xxxxxxxxxxxxxxxxxxxxx’ does not have authorization to perform action ‘Microsoft.Network/networkSecurityGroups/write’ over scope ‘/subscriptions/xxxxxxxxxxxxxxxxxxx/resourceGroups/RG-Bill/providers/Microsoft.Network/networkSecurityGroups/testvm00201’ or the scope is invalid. If access was recently granted, please refresh your credentials.\nCode: AuthorizationFailed\nMessage: The client ‘xxxxxxxxxxxxxxxxxxx’ with object id ‘xxxxxxxxxxxxxxxxxxxxxxxxxxxxx’ does not have authorization to perform action ‘Microsoft.Network/networkSecurityGroups/write’ over scope ‘/subscriptions/xxxxxxxxxxxxxxxxxxxxxxxxxxxxx/resourceGroups/RG-Bill/providers/Microsoft.Network/networkSecurityGroups/testvm00201’ or the scope is invalid. If access was recently granted, please refresh your credentials.”,

I think I know what the problem is; to me it looks like it is trying to create a NSG and I do not have privs for that, so the way to resolve this is tell my PB to use a network that is already setup, but the network that is already setup is in a different resource group (RG-Net) and my VM is being build in RG-Bill so my question is how to I tell it to use my existing network (VNET1) and subnet (SUBNET\_VNET1) that is in the resource group RG\_Net?

I looked up and thought I could set it via:

virtual\_network\_resource\_group: RG-Net

virtual\_network\_name: VNET1

But as you can see it threw the error yet again, really am stuck here, what do you think?

Thanks in Advance

Bill
