-
Notifications
You must be signed in to change notification settings - Fork 1
/
create-vm.yml
103 lines (101 loc) · 2.93 KB
/
create-vm.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Create a VM for an ansible control host set up for remote collaboration
- name: Create VM
hosts: localhost
connection: local
tasks:
- name: Create resource group
azure_rm_resourcegroup:
name: "{{ rgname }}"
location: "{{ location }}"
- name: Create virtual network
azure_rm_virtualnetwork:
resource_group: "{{ rgname }}"
name: "{{ rgname }}_vnet"
address_prefixes: "10.0.0.0/16"
- name: Add subnet
azure_rm_subnet:
resource_group: "{{ rgname }}"
name: "{{ rgname }}_subnet"
address_prefix: "10.0.1.0/24"
virtual_network: "{{ rgname }}_vnet"
- name: Create public IP address
azure_rm_publicipaddress:
resource_group: "{{ rgname }}"
allocation_method: Static
name: "{{ rgname }}_pubip"
register: pub_ip
- name: Create Network Security Group allowing SSH
azure_rm_securitygroup:
resource_group: "{{ rgname }}"
name: "{{ rgname }}_nsg"
rules:
- name: SSH
protocol: Tcp
destination_port_range: 22
access: Allow
priority: 1001
direction: Inbound
- name: Create virtual network interface card for master VM
azure_rm_networkinterface:
resource_group: "{{ rgname }}"
name: "{{ rgname }}_masternic"
virtual_network: "{{ rgname }}_vnet"
subnet_name: "{{rgname }}_subnet"
security_group: "{{ rgname }}_nsg"
ip_configurations:
- name: 'default'
primary: yes
public_ip_address_name: "{{ rgname }}_pubip"
- name: Create master VM
azure_rm_virtualmachine:
resource_group: "{{ rgname }}"
name: "{{ rgname }}-vm"
vm_size: "{{ vm_size }}"
admin_username: "{{ admin_user }}"
ssh_password_enabled: false
ssh_public_keys: "{{ admin_pub_keys }}"
network_interfaces: "{{ rgname }}_masternic"
image:
offer: "{{ image.offer }}"
publisher: "{{ image.publisher }}"
sku: "{{ image.sku }}"
version: latest
- debug:
msg: "VM public IP address {{ pub_ip.state.ip_address }}"
- name: create inventory
add_host:
name: "{{ pub_ip.state.ip_address }}"
groups: ansible_control
- name: install ansible
hosts: ansible_control
user: "{{ admin_user }}"
tasks:
- yum:
name: gcc,libffi-devel,python-devel,openssl-devel
become: yes
- yum:
name: epel-release
enablerepo: extras
state: present
become: yes
- yum:
name: python-pip,python-wheel
state: present
become: yes
- name: install ansible
pip:
name: "ansible[azure]"
state: present
become: yes
- file:
path: /home/{{ admin_user }}/.azure
state: directory
- name: copy credentials
copy:
src: "{{ cred_path }}"
dest: /home/{{ admin_user }}/.azure/credentials
- name: install tmux
yum:
name: tmux
state: present
become: yes