forked from Azure-Samples/ansible-playbooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_virtualmachine_with_subnet_in_different_resource_group.yml
51 lines (50 loc) · 1.73 KB
/
create_virtualmachine_with_subnet_in_different_resource_group.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Description
# ===========
# This playbook create an Azure VM with public IP, and subnet in another resource group.
# This Script will create two resource group, defined by variables resource_group and resource_group_secondary.
# Then it creates VM in resource_group and virtual network with defined subnets,nsg rules in resource_group_secondary.
- name: Create Azure VM
hosts: localhost
connection: local
vars:
resource_group: "{{ resource_group_name }}"
resource_group_secondary: createvmsubnetin2ndrg2
vm_name: testvm
location: eastus
# roles:
# - azure.azure_preview_modules
tasks:
- name: Create a resource group
azure_rm_resourcegroup:
name: "{{ resource_group }}"
location: "{{ location }}"
- name: Create secondary resource group
azure_rm_resourcegroup:
name: "{{ resource_group_secondary }}"
location: "{{ location }}"
- name: Create virtual network
azure_rm_virtualnetwork:
resource_group: "{{ resource_group_secondary }}"
name: "{{ vm_name }}"
address_prefixes: "10.0.0.0/16"
- name: Add subnet
azure_rm_subnet:
resource_group: "{{ resource_group_secondary }}"
name: "{{ vm_name }}"
address_prefix: "10.0.1.0/24"
virtual_network: "{{ vm_name }}"
- name: Create VM
azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: "{{ vm_name }}"
vm_size: Standard_DS1_v2
admin_username: azureuser
admin_password: Password@123
virtual_network_resource_group: "{{ resource_group_secondary }}"
virtual_network_name: "{{ vm_name }}"
subnet_name: "{{ vm_name }}"
image:
offer: UbuntuServer
publisher: Canonical
sku: 16.04-LTS
version: latest