# Ansible and Azure

**URL:** <https://forum.ansible.com/t/ansible-and-azure/31189>\
**Category:** Ansible Project\
**Tags:** azure, windows\
**Created:** [September 3, 2019, 2:57pm UTC](https://forum.ansible.com/t/ansible-and-azure/31189 "2019-09-03T14:57:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lucas\_Chies](https://avatars.discourse-cdn.com/v4/letter/l/5e9695/32.png) [@Lucas\_Chies](https://forum.ansible.com/u/Lucas_Chies)\
**Post date:** [September 3, 2019, 2:57pm UTC](https://forum.ansible.com/t/ansible-and-azure/31189/1 "2019-09-03T14:57:09Z")

</div>

Hello guys,  
I’ve a doubt … I’ve a ansible script that create an windows VM on Azure, but I already have the vnet created in and hosted in another Resource Group.  
I don’t know how can I create my script to put this VM in the created vNet.

I tried to put this:

virtual\_network\_name:  
resource\_group: rg-fgl-network  
name: vnet-fgl  
location: brazilsouth

But is not working.

Someone already tried this?

---

<div class="post-metadata">

**Author:** ![Wawrzek\_Niewodniczan](https://avatars.discourse-cdn.com/v4/letter/w/bbe5ce/32.png) [@Wawrzek\_Niewodniczan](https://forum.ansible.com/u/Wawrzek_Niewodniczan)\
**Post date:** [September 3, 2019, 3:37pm UTC](https://forum.ansible.com/t/ansible-and-azure/31189/2 "2019-09-03T15:37:54Z")

</div>

> Hello guys,  
> I've a doubt ... I've a ansible script that create an windows VM on Azure, but I already have the vnet created in and hosted in another Resource Group.  
> I don't know how can I create my script to put this VM in the created vNet.
> 
> I tried to put this:

[...]

> But is not working.

What's the error message? Vnet and VM doesn't need to be in on RG.

Wawrzek

---

<div class="post-metadata">

**Author:** ![Lucas\_Chies](https://avatars.discourse-cdn.com/v4/letter/l/5e9695/32.png) [@Lucas\_Chies](https://forum.ansible.com/u/Lucas_Chies)\
**Post date:** [September 3, 2019, 5:20pm UTC](https://forum.ansible.com/t/ansible-and-azure/31189/3 "2019-09-03T17:20:32Z")

</div>

Hi @Wawrzek,

Yes, they need be in a RG. But in my case the VM will be in one RG and the vNet already existing in another RG.

But I achieve this using this :

- name: Create Azure VM  
hosts: localhost  
connection: local  
vars:  
resource\_group\_vnet: rgname  
vnet\_name: vnetname  
subnet\_name: subnetname

and after the image information, I put this:

virtual\_network\_resource\_group: “{{ resource\_group\_vnet }}”  
virtual\_network\_name: “{{ vnet\_name }}”  
subnet\_name: “{{ subnet\_name }}”

After this, the vm was created in your resource and consume the vNet in another RG.

Tks.

---

<div class="post-metadata">

**Author:** ![Wawrzek\_Niewodniczan](https://avatars.discourse-cdn.com/v4/letter/w/bbe5ce/32.png) [@Wawrzek\_Niewodniczan](https://forum.ansible.com/u/Wawrzek_Niewodniczan)\
**Post date:** [September 4, 2019, 8:16am UTC](https://forum.ansible.com/t/ansible-and-azure/31189/4 "2019-09-04T08:16:33Z")

</div>

Hi Lucas,

> Yes, they need be in a RG. But in my case the VM will be in one RG and the vNet already existing in another RG.

What I meant is they don't need to be in the same RG, but I see that  
you find the right approach out.

Wawrzek
