-
Notifications
You must be signed in to change notification settings - Fork 350
/
vm_create_with_nic_in_other_rg.yml
83 lines (77 loc) · 3.06 KB
/
vm_create_with_nic_in_other_rg.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Description
# ===========
# This playbook creates an Azure Network Interface.
# Then creates an Azure Virtual Machine in another resource group, attach Azure Network Interface from last step.
# Change variables below to customize your VM deployment.
- hosts: localhost
vars:
prefix: ansiblesample
nicResourceGroup: "{{ resource_group_name }}nic"
vmResourceGroup: "{{ resource_group_name }}"
StartCount: 1
EndCount: 2
adminUser: ansiblesample
roles:
- { role: azure.azure_preview_modules }
tasks:
- name: Create resource group
azure_rm_resourcegroup:
name: "{{ item }}"
location: eastus
with_items:
- "{{ nicResourceGroup }}"
- "{{ vmResourceGroup }}"
- name: Create virtual network
azure_rm_virtualnetwork:
resource_group: "{{ nicResourceGroup }}"
name: "{{prefix}}vn"
address_prefixes: "10.10.0.0/16"
- name: Add subnet
azure_rm_subnet:
resource_group: "{{ nicResourceGroup }}"
name: "{{prefix}}subnet"
address_prefix: "10.10.0.0/24"
virtual_network: "{{prefix}}vn"
- name: Create Public IP
azure_rm_publicipaddress:
resource_group: "{{ nicResourceGroup }}"
name: "{{prefix}}pip{{item}}"
allocation_method: Dynamic
with_sequence: start="{{StartCount}}" end="{{EndCount}}"
- name: Create a network interface with Public IP
azure_rm_networkinterface:
name: "{{prefix}}nic{{item}}"
resource_group: "{{nicResourceGroup}}"
security_group_name: "{{prefix}}nsg"
subnet_name: "{{prefix}}subnet"
virtual_network_name: "{{prefix}}vn"
ip_configurations:
- name: ipconfigs
primary: True
public_ip_name: "{{prefix}}pip{{item}}"
tags:
environment: dev
with_sequence: start="{{StartCount}}" end="{{EndCount}}"
- name: "Create a virtual machine with network interface"
azure_rm_virtualmachine:
admin_username: "{{adminUser}}"
image:
offer: CentOS
publisher: OpenLogic
sku: "7.3"
version: latest
managed_disk_type: Standard_LRS
name: "{{prefix}}vm{{item}}"
network_interfaces:
- name: "{{prefix}}nic{{item}}"
resource_group: "{{ nicResourceGroup }}"
os_disk_caching: ReadWrite
resource_group: "{{ vmResourceGroup }}"
ssh_password_enabled: false
ssh_public_keys:
- key_data: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDVeZj8ACqIMakHaaO5c/2Qp4/eEzkGR6EP4W7BANOKjdd9rs7mgDzPbXXgo6aIQQ2mlRGJClHjWARATJUaX/FqJrRizY35qyYh5GKzv9WMVImRIAGAgAY40TcomRBBNZWGmKHja0Za7oLSW8CtmZYNphMcWB6rB2Ckkrovz6JZrB0ptHtv0J7pkSzlULJNYX8RxriipIyIrYpa3W2WTY4iqHZnVhfulctAf/Lci1TW0sWrPt8qSlG9lhbBvBBmI8AJNxjEiuHMdiiBx5v3MKfM98+wdlUh5tgkkUfoc8bBhevY1M63GwPHnf96xeR2JnvOmgLfVeCsGzKrxY0X6IPl bitest@sac-jumpbox0"
path: "/home/{{adminUser}}/.ssh/authorized_keys"
tags:
environment: dev
vm_size: Standard_B2s
with_sequence: start="{{StartCount}}" end="{{EndCount}}"