1---
2- name: Create volume in check mode
3  cloudscale_volume:
4    name: '{{ cloudscale_resource_prefix }}-vol'
5    size_gb: 50
6    tags:
7      project: ansible-test
8      stage: production
9      sla: 24-7
10  check_mode: yes
11  register: vol
12- name: 'VERIFY: Create volume in check mode'
13  assert:
14    that:
15      - vol is successful
16      - vol is changed
17      - vol.state == 'absent'
18
19- name: Create volume
20  cloudscale_volume:
21    name: '{{ cloudscale_resource_prefix }}-vol'
22    size_gb: 50
23    tags:
24      project: ansible-test
25      stage: production
26      sla: 24-7
27  register: vol
28- name: 'VERIFY: Create volume'
29  assert:
30    that:
31      - vol is successful
32      - vol is changed
33      - vol.size_gb == 50
34      - vol.name == '{{ cloudscale_resource_prefix }}-vol'
35      - vol.tags.project == 'ansible-test'
36      - vol.tags.stage == 'production'
37      - vol.tags.sla == '24-7'
38
39- name: Create volume indempotence
40  cloudscale_volume:
41    name: '{{ cloudscale_resource_prefix }}-vol'
42    size_gb: 50
43    tags:
44      project: ansible-test
45      stage: production
46      sla: 24-7
47  register: vol
48- name: 'VERIFY: Create volume indempotence'
49  assert:
50    that:
51      - vol is successful
52      - vol is not changed
53      - vol.size_gb == 50
54      - vol.name == '{{ cloudscale_resource_prefix }}-vol'
55      - vol.tags.project == 'ansible-test'
56      - vol.tags.stage == 'production'
57      - vol.tags.sla == '24-7'
58
59- name: Attach existing volume by name to server in check mode
60  cloudscale_volume:
61    name: '{{ cloudscale_resource_prefix }}-vol'
62    server_uuids:
63      - '{{ server.uuid }}'
64  check_mode: yes
65  register: vol
66- name: 'VERIFY: Attach existing volume by name to server in check mode'
67  assert:
68    that:
69      - vol is successful
70      - vol is changed
71      - server.uuid not in vol.server_uuids
72
73- name: Attach existing volume by name to server
74  cloudscale_volume:
75    name: '{{ cloudscale_resource_prefix }}-vol'
76    server_uuids:
77      - '{{ server.uuid }}'
78  register: vol
79- name: 'VERIFY: Attach existing volume by name to server'
80  assert:
81    that:
82      - vol is successful
83      - vol is changed
84      - server.uuid in vol.server_uuids
85
86- name: Attach existing volume by name to server indempotence
87  cloudscale_volume:
88    name: '{{ cloudscale_resource_prefix }}-vol'
89    server_uuids:
90      - '{{ server.uuid }}'
91  register: vol
92- name: 'VERIFY: Attach existing volume by name to server indempotence'
93  assert:
94    that:
95      - vol is successful
96      - vol is not changed
97      - server.uuid in vol.server_uuids
98
99- name: Resize attached volume by UUID in check mode
100  cloudscale_volume:
101    uuid: '{{ vol.uuid }}'
102    size_gb: 100
103  check_mode: yes
104  register: vol
105- name: 'VERIFY: Resize attached volume by UUID in check mode'
106  assert:
107    that:
108      - vol is successful
109      - vol is changed
110      - vol.size_gb == 50
111
112- name: Resize attached volume by UUID
113  cloudscale_volume:
114    uuid: '{{ vol.uuid }}'
115    size_gb: 100
116  register: vol
117- name: 'VERIFY: Resize attached volume by UUID'
118  assert:
119    that:
120      - vol is successful
121      - vol is changed
122      - vol.size_gb == 100
123
124- name: Resize attached volume by UUID indempotence
125  cloudscale_volume:
126    uuid: '{{ vol.uuid }}'
127    size_gb: 100
128  register: vol
129- name: 'VERIFY: Resize attached volume by UUID indempotence'
130  assert:
131    that:
132      - vol is successful
133      - vol is not changed
134      - vol.size_gb == 100
135
136- name: Delete attached volume by UUID in check mode
137  cloudscale_volume:
138    uuid: '{{ vol.uuid }}'
139    state: 'absent'
140  check_mode: yes
141  register: deleted
142- name: 'VERIFY: Delete attached volume by UUID in check mode'
143  assert:
144    that:
145      - deleted is successful
146      - deleted is changed
147      - deleted.state == 'present'
148      - deleted.uuid == vol.uuid
149      - deleted.name == '{{ cloudscale_resource_prefix }}-vol'
150
151- name: Delete attached volume by UUID
152  cloudscale_volume:
153    uuid: '{{ vol.uuid }}'
154    state: 'absent'
155  register: deleted
156- name: 'VERIFY: Delete attached volume by UUID'
157  assert:
158    that:
159      - deleted is successful
160      - deleted is changed
161      - deleted.state == 'absent'
162      - deleted.uuid == vol.uuid
163      - deleted.name == '{{ cloudscale_resource_prefix }}-vol'
164
165- name: Delete attached volume by UUID indempotence
166  cloudscale_volume:
167    uuid: '{{ vol.uuid }}'
168    state: 'absent'
169  register: deleted
170- name: 'VERIFY: Delete attached volume by UUID indempotence'
171  assert:
172    that:
173      - deleted is successful
174      - deleted is not changed
175      - deleted.state == 'absent'
176      - deleted.uuid == vol.uuid
177      - not deleted.name
178
179- name: Create bulk volume and attach
180  cloudscale_volume:
181    name: '{{ cloudscale_resource_prefix }}-bulk'
182    type: bulk
183    size_gb: 100
184    server_uuids:
185      - '{{ server.uuid }}'
186  register: bulk
187- name: 'VERIFY: Create bulk volume and attach'
188  assert:
189    that:
190      - bulk is successful
191      - bulk is changed
192      - bulk.size_gb == 100
193      - server.uuid in bulk.server_uuids
194
195- name: Detach volume by UUID
196  cloudscale_volume:
197    uuid: '{{ bulk.uuid }}'
198    server_uuids: []
199  register: bulk
200- name: 'VERIFY: Detach volume by UUID'
201  assert:
202    that:
203      - bulk is successful
204      - bulk is changed
205      - bulk.server_uuids == []
206
207- name: Resize detached volume by name
208  cloudscale_volume:
209    name: '{{ bulk.name }}'
210    size_gb: 200
211  register: bulk
212- name: 'VERIFY: Resize detached volume by name'
213  assert:
214    that:
215      - bulk is successful
216      - bulk is changed
217      - bulk.size_gb == 200
218
219- name: Delete volume by name in check mode
220  cloudscale_volume:
221    name: '{{ bulk.name }}'
222    state: 'absent'
223  check_mode: yes
224  register: bulk
225- name: 'VERIFY: Delete volume by name'
226  assert:
227    that:
228      - bulk is successful
229      - bulk is changed
230      - bulk.state == 'present'
231
232- name: Delete volume by name
233  cloudscale_volume:
234    name: '{{ bulk.name }}'
235    state: 'absent'
236  register: bulk
237- name: 'VERIFY: Delete volume by name'
238  assert:
239    that:
240      - bulk is successful
241      - bulk is changed
242      - bulk.state == 'absent'
243
244- name: Delete volume by name idempotence
245  cloudscale_volume:
246    name: '{{ bulk.name }}'
247    state: 'absent'
248  register: bulk
249- name: 'VERIFY: Delete volume by name idempotence'
250  assert:
251    that:
252      - bulk is successful
253      - bulk is not changed
254      - bulk.state == 'absent'
255
256- import_tasks: failures.yml
257