blob: 3abaaefb63434d831425f9a16d5443281d370592 (
plain)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
- name: Prepare random number
set_fact:
rpfx: "{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}"
parameter: {}
run_once: yes
- name: Clearing (if) previous disks were created
azure_rm_manageddisk:
resource_group: "{{ resource_group }}"
name: "md{{ rpfx }}{{ item }}"
managed_by: ''
state: absent
with_items:
- 1
- 2
- 3
- name: Test invalid account name (should give error)
azure_rm_manageddisk:
resource_group: "{{ resource_group }}"
name: "invalid_char$"
disk_size_gb: 1
register: output
ignore_errors: yes
check_mode: no
- name: Assert task failed
assert: { that: "output['failed'] == True" }
- name: Create managed disk (Check Mode)
azure_rm_manageddisk:
resource_group: "{{ resource_group }}"
name: "md{{ rpfx }}1"
storage_account_type: "Standard_LRS"
disk_size_gb: 1
tags:
testing: testing
delete: never
register: output
check_mode: yes
- name: Assert status succeeded (Check Mode)
assert:
that:
- output.changed
- output.state
- name: Create new managed disk succesfully
azure_rm_manageddisk:
resource_group: "{{ resource_group }}"
name: "md{{ rpfx }}1"
storage_account_type: "Standard_LRS"
disk_size_gb: 1
tags:
testing: testing
delete: never
register: output
- name: Assert status succeeded and results include an Id value
assert:
that:
- output.changed
- output.state.disk_size_gb == 1
- output.state.id is defined
- output.state.os_type == None
- output.state.storage_account_type == "Standard_LRS"
- name: Copy disk to a new managed disk
azure_rm_manageddisk:
resource_group: "{{ resource_group }}"
name: "md{{ rpfx }}2"
create_option: "copy"
source_uri: "{{ output.state.id }}"
disk_size_gb: 1
register: disk2
- name: Assert status succeeded and results include an Id value
assert:
that:
- disk2.changed
- disk2.state.id is defined
- name: Create disk to a new managed disk with zone and os type
azure_rm_manageddisk:
resource_group: "{{ resource_group }}"
name: "md{{ rpfx }}3"
source_uri: "{{ output.state.id }}"
disk_size_gb: 1
zone: "1"
os_type: windows
register: disk3
- name: Assert status succeeded and results include an Id value
assert:
that:
- disk3.changed
- disk3.state.id is defined
- disk3.state.zone == "1"
- disk3.state.os_type == "windows"
- name: Change storage account type to an invalid type
azure_rm_manageddisk:
resource_group: "{{ resource_group }}"
name: "md{{ rpfx }}1"
storage_account_type: "PremiumL"
disk_size_gb: 1
register: output
ignore_errors: yes
- name: Assert storage account type change failed
assert: { that: "output['failed'] == True" }
- name: Update disk options (os_type, account_type, size, tags)
azure_rm_manageddisk:
resource_group: "{{ resource_group }}"
name: "md{{ rpfx }}1"
disk_size_gb: 2
os_type: linux
storage_account_type: "StandardSSD_LRS"
tags:
galaxy: "no"
delete: never
register: output
- assert:
that:
- output.changed
- output.state.storage_account_type == "StandardSSD_LRS"
- output.state.disk_size_gb == 2
- "output.state.tags | length == 2"
- "output.state.tags.galaxy == 'no'"
- output.state.os_type == 'linux'
- name: Gather facts to one specific disk
azure_rm_manageddisk_info:
resource_group: "{{ resource_group }}"
name: "md{{ rpfx }}1"
register: output
- assert:
that:
- "output.ansible_info.azure_managed_disk | length == 1"
- output.ansible_info.azure_managed_disk[0].storage_account_type == "StandardSSD_LRS"
- output.ansible_info.azure_managed_disk[0].disk_size_gb == 2
- "output.ansible_info.azure_managed_disk[0].os_type == 'linux'"
- set_fact:
parameter: "{{parameter |combine({item.key: item.value})}}"
when: "{{item.key not in ['id', 'changed'] and item.value != None}}"
with_dict: "{{ output.ansible_info.azure_managed_disk[0] }}"
- name: Create disk with facts return value
azure_rm_manageddisk:
resource_group: "{{ resource_group }}"
location: "{{ parameter.location }}"
name: "{{ parameter.name }}"
storage_account_type: "{{ parameter.storage_account_type }}"
disk_size_gb: "{{ parameter.disk_size_gb }}"
create_option: "{{ parameter.create_option }}"
tags: "{{ parameter.tags }}"
register: output
- assert:
that:
- not output.changed
- name: Delete managed disk (Check Mode)
azure_rm_manageddisk:
resource_group: "{{ resource_group }}"
name: "md{{ rpfx }}1"
state: absent
register: output
check_mode: yes
- name: Assert status succeeded
assert:
that:
- output.changed
- output.state
- name: Delete all managed disk
azure_rm_manageddisk:
resource_group: "{{ resource_group }}"
name: "md{{ rpfx }}{{ item }}"
managed_by: ''
state: absent
with_items:
- 1
- 2
- 3
- name: Delete virtual machine
azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: "tr{{ rpfx }}"
state: absent
vm_size: Standard_DS1_v2
- name: Delete public ip
azure_rm_publicipaddress:
resource_group: "{{ resource_group }}"
allocation_method: Static
name: "tr{{ rpfx }}"
state: absent
|