| 1 |
--- |
| 2 |
- module_defaults: |
| 3 |
group/aws: |
| 4 |
access_key: "{{ aws_access_key }}" |
| 5 |
secret_key: "{{ aws_secret_key }}" |
| 6 |
session_token: "{{ security_token | default(omit) }}" |
| 7 |
region: "{{ aws_region }}" |
| 8 |
|
| 9 |
block: |
| 10 |
- name: Create a test VPC |
| 11 |
amazon.aws.ec2_vpc_net: |
| 12 |
name: "{{ vpc_name }}" |
| 13 |
cidr_block: "{{ vpc_cidr }}" |
| 14 |
tags: |
| 15 |
Name: ec2_vol testing |
| 16 |
ResourcePrefix: "{{ resource_prefix }}" |
| 17 |
register: testing_vpc |
| 18 |
|
| 19 |
- name: Create a test subnet |
| 20 |
amazon.aws.ec2_vpc_subnet: |
| 21 |
vpc_id: "{{ testing_vpc.vpc.id }}" |
| 22 |
cidr: "{{ subnet_cidr }}" |
| 23 |
tags: |
| 24 |
Name: ec2_vol testing |
| 25 |
ResourcePrefix: "{{ resource_prefix }}" |
| 26 |
az: "{{ availability_zone }}" |
| 27 |
register: testing_subnet |
| 28 |
|
| 29 |
- name: Create an ec2 instance |
| 30 |
amazon.aws.ec2_instance: |
| 31 |
name: "{{ instance_name }}" |
| 32 |
vpc_subnet_id: "{{ testing_subnet.subnet.id }}" |
| 33 |
instance_type: t3.nano |
| 34 |
image_id: "{{ ec2_ami_id }}" |
| 35 |
tags: |
| 36 |
ResourcePrefix: "{{ resource_prefix }}" |
| 37 |
register: test_instance |
| 38 |
|
| 39 |
- name: Check task return attributes |
| 40 |
ansible.builtin.assert: |
| 41 |
that: |
| 42 |
- test_instance.changed |
| 43 |
|
| 44 |
- name: Create another ec2 instance |
| 45 |
amazon.aws.ec2_instance: |
| 46 |
name: "{{ instance_name }}-2" |
| 47 |
vpc_subnet_id: "{{ testing_subnet.subnet.id }}" |
| 48 |
instance_type: t3.nano |
| 49 |
image_id: "{{ ec2_ami_id }}" |
| 50 |
tags: |
| 51 |
ResourcePrefix: "{{ resource_prefix }}" |
| 52 |
register: test_instance_2 |
| 53 |
|
| 54 |
- name: Check task return attributes |
| 55 |
ansible.builtin.assert: |
| 56 |
that: |
| 57 |
- test_instance_2.changed |
| 58 |
|
| 59 |
- name: Create another ec2 instance |
| 60 |
amazon.aws.ec2_instance: |
| 61 |
name: "{{ instance_name }}-3" |
| 62 |
vpc_subnet_id: "{{ testing_subnet.subnet.id }}" |
| 63 |
instance_type: t3.nano |
| 64 |
image_id: "{{ ec2_ami_id }}" |
| 65 |
tags: |
| 66 |
ResourcePrefix: "{{ resource_prefix }}" |
| 67 |
register: test_instance_3 |
| 68 |
|
| 69 |
- name: Check task return attributes |
| 70 |
ansible.builtin.assert: |
| 71 |
that: |
| 72 |
- test_instance_3.changed |
| 73 |
|
| 74 |
# # ==== ec2_vol tests =============================================== |
| 75 |
|
| 76 |
- name: Create a volume (validate module defaults - check_mode) |
| 77 |
amazon.aws.ec2_vol: |
| 78 |
volume_size: 1 |
| 79 |
zone: "{{ availability_zone }}" |
| 80 |
tags: |
| 81 |
ResourcePrefix: "{{ resource_prefix }}" |
| 82 |
check_mode: true |
| 83 |
register: volume1_check_mode |
| 84 |
|
| 85 |
- ansible.builtin.assert: |
| 86 |
that: |
| 87 |
- volume1_check_mode is changed |
| 88 |
|
| 89 |
- name: Create a volume (validate module defaults) |
| 90 |
amazon.aws.ec2_vol: |
| 91 |
volume_size: 1 |
| 92 |
zone: "{{ availability_zone }}" |
| 93 |
tags: |
| 94 |
ResourcePrefix: "{{ resource_prefix }}" |
| 95 |
register: volume1 |
| 96 |
|
| 97 |
- name: Check task return attributes |
| 98 |
ansible.builtin.assert: |
| 99 |
that: |
| 100 |
- volume1.changed |
| 101 |
- "'volume' in volume1" |
| 102 |
- "'volume_id' in volume1" |
| 103 |
- "'volume_type' in volume1" |
| 104 |
- "'device' in volume1" |
| 105 |
- volume1.volume.status == 'available' |
| 106 |
- volume1.volume_type == 'standard' |
| 107 |
- "'attachment_set' in volume1.volume" |
| 108 |
- volume1.volume.attachment_set | length == 0 |
| 109 |
- not ("Name" in volume1.volume.tags) |
| 110 |
- not volume1.volume.encrypted |
| 111 |
- volume1.volume.tags.ResourcePrefix == resource_prefix |
| 112 |
|
| 113 |
# no idempotency check needed here |
| 114 |
|
| 115 |
- name: Create another volume (override module defaults) |
| 116 |
amazon.aws.ec2_vol: |
| 117 |
encrypted: true |
| 118 |
volume_size: 4 |
| 119 |
volume_type: io1 |
| 120 |
iops: 101 |
| 121 |
name: "{{ resource_prefix }}" |
| 122 |
tags: |
| 123 |
ResourcePrefix: "{{ resource_prefix }}" |
| 124 |
zone: "{{ availability_zone }}" |
| 125 |
register: volume2 |
| 126 |
|
| 127 |
- name: Check task return attributes |
| 128 |
ansible.builtin.assert: |
| 129 |
that: |
| 130 |
- volume2.changed |
| 131 |
- "'volume' in volume2" |
| 132 |
- "'volume_id' in volume2" |
| 133 |
- "'volume_type' in volume2" |
| 134 |
- "'device' in volume2" |
| 135 |
- volume2.volume.status == 'available' |
| 136 |
- volume2.volume_type == 'io1' |
| 137 |
- volume2.volume.iops == 101 |
| 138 |
- volume2.volume.size == 4 |
| 139 |
- volume2.volume.tags.Name == resource_prefix |
| 140 |
- volume2.volume.encrypted |
| 141 |
- volume2.volume.tags.ResourcePrefix == resource_prefix |
| 142 |
|
| 143 |
- name: Create another volume (override module defaults) (idempotent) |
| 144 |
amazon.aws.ec2_vol: |
| 145 |
encrypted: true |
| 146 |
volume_size: 4 |
| 147 |
volume_type: io1 |
| 148 |
iops: 101 |
| 149 |
name: "{{ resource_prefix }}" |
| 150 |
tags: |
| 151 |
ResourcePrefix: "{{ resource_prefix }}" |
| 152 |
zone: "{{ availability_zone }}" |
| 153 |
register: volume2_idem |
| 154 |
|
| 155 |
- name: Check task return attributes |
| 156 |
ansible.builtin.assert: |
| 157 |
that: |
| 158 |
- not volume2_idem.changed |
| 159 |
|
| 160 |
- name: Create snapshot from volume |
| 161 |
amazon.aws.ec2_snapshot: |
| 162 |
volume_id: "{{ volume1.volume_id }}" |
| 163 |
description: Resource Prefix - {{ resource_prefix }} |
| 164 |
snapshot_tags: |
| 165 |
ResourcePrefix: "{{ resource_prefix }}" |
| 166 |
register: vol1_snapshot |
| 167 |
|
| 168 |
- name: Check task return attributes |
| 169 |
ansible.builtin.assert: |
| 170 |
that: |
| 171 |
- vol1_snapshot.changed |
| 172 |
|
| 173 |
- name: Create a volume from a snapshot (check_mode) |
| 174 |
amazon.aws.ec2_vol: |
| 175 |
snapshot: "{{ vol1_snapshot.snapshot_id }}" |
| 176 |
encrypted: true |
| 177 |
volume_type: gp2 |
| 178 |
volume_size: 1 |
| 179 |
zone: "{{ availability_zone }}" |
| 180 |
tags: |
| 181 |
ResourcePrefix: "{{ resource_prefix }}" |
| 182 |
check_mode: true |
| 183 |
register: volume3_check_mode |
| 184 |
|
| 185 |
- name: Check task return attributes |
| 186 |
ansible.builtin.assert: |
| 187 |
that: |
| 188 |
- volume3_check_mode.changed |
| 189 |
|
| 190 |
- name: Create a volume from a snapshot |
| 191 |
amazon.aws.ec2_vol: |
| 192 |
snapshot: "{{ vol1_snapshot.snapshot_id }}" |
| 193 |
encrypted: true |
| 194 |
volume_type: gp2 |
| 195 |
volume_size: 1 |
| 196 |
zone: "{{ availability_zone }}" |
| 197 |
tags: |
| 198 |
ResourcePrefix: "{{ resource_prefix }}" |
| 199 |
register: volume3 |
| 200 |
|
| 201 |
- name: Check task return attributes |
| 202 |
ansible.builtin.assert: |
| 203 |
that: |
| 204 |
- volume3.changed |
| 205 |
- volume3.volume.snapshot_id == vol1_snapshot.snapshot_id |
| 206 |
|
| 207 |
- name: Create a volume from a snapshot with initialization rate (check_mode) |
| 208 |
amazon.aws.ec2_vol: |
| 209 |
snapshot: "{{ vol1_snapshot.snapshot_id }}" |
| 210 |
volume_initialization_rate: 100 |
| 211 |
encrypted: true |
| 212 |
volume_type: gp2 |
| 213 |
volume_size: 1 |
| 214 |
zone: "{{ availability_zone }}" |
| 215 |
tags: |
| 216 |
ResourcePrefix: "{{ resource_prefix }}" |
| 217 |
check_mode: true |
| 218 |
register: volume4_check_mode |
| 219 |
vars: |
| 220 |
ansible_python_interpreter: "{{ botocore_virtualenv_interpreter }}" |
| 221 |
|
| 222 |
- name: Check task return attributes |
| 223 |
ansible.builtin.assert: |
| 224 |
that: |
| 225 |
- volume4_check_mode.changed |
| 226 |
|
| 227 |
- name: Create a volume from a snapshot |
| 228 |
amazon.aws.ec2_vol: |
| 229 |
snapshot: "{{ vol1_snapshot.snapshot_id }}" |
| 230 |
volume_initialization_rate: 100 |
| 231 |
encrypted: true |
| 232 |
volume_type: gp2 |
| 233 |
volume_size: 1 |
| 234 |
zone: "{{ availability_zone }}" |
| 235 |
tags: |
| 236 |
ResourcePrefix: "{{ resource_prefix }}" |
| 237 |
register: volume4 |
| 238 |
vars: |
| 239 |
ansible_python_interpreter: "{{ botocore_virtualenv_interpreter }}" |
| 240 |
|
| 241 |
- name: Check task return attributes |
| 242 |
ansible.builtin.assert: |
| 243 |
that: |
| 244 |
- volume4.changed |
| 245 |
- volume4.volume.snapshot_id == vol1_snapshot.snapshot_id |
| 246 |
|
| 247 |
- name: Wait for instance to start |
| 248 |
amazon.aws.ec2_instance: |
| 249 |
state: running |
| 250 |
instance_ids: "{{ test_instance.instance_ids }}" |
| 251 |
wait: true |
| 252 |
|
| 253 |
- name: Attach existing volume to an instance (check_mode) |
| 254 |
amazon.aws.ec2_vol: |
| 255 |
id: "{{ volume1.volume_id }}" |
| 256 |
instance: "{{ test_instance.instance_ids[0] }}" |
| 257 |
device_name: /dev/sdg |
| 258 |
delete_on_termination: false |
| 259 |
check_mode: true |
| 260 |
register: vol_attach_result_check_mode |
| 261 |
|
| 262 |
- ansible.builtin.assert: |
| 263 |
that: |
| 264 |
- vol_attach_result_check_mode is changed |
| 265 |
|
| 266 |
- name: Attach existing volume to an instance |
| 267 |
amazon.aws.ec2_vol: |
| 268 |
id: "{{ volume1.volume_id }}" |
| 269 |
instance: "{{ test_instance.instance_ids[0] }}" |
| 270 |
device_name: /dev/sdg |
| 271 |
delete_on_termination: false |
| 272 |
register: vol_attach_result |
| 273 |
|
| 274 |
- name: Check task return attributes |
| 275 |
ansible.builtin.assert: |
| 276 |
that: |
| 277 |
- vol_attach_result.changed |
| 278 |
- "'device' in vol_attach_result and vol_attach_result.device == '/dev/sdg'" |
| 279 |
- "'volume' in vol_attach_result" |
| 280 |
|
| 281 |
# There's a delay between the volume being "In Use", and the attachment being reported. This |
| 282 |
# can result in a race condition on the results. (There's no clean waiter to use either) |
| 283 |
- name: Wait for volume to report attached/attaching |
| 284 |
amazon.aws.ec2_vol_info: |
| 285 |
filters: |
| 286 |
volume-id: "{{ volume1.volume_id }}" |
| 287 |
register: vol_attach_info |
| 288 |
until: |
| 289 |
- vol_attach_info.volumes[0].attachment_set | length >=1 |
| 290 |
retries: 5 |
| 291 |
delay: 2 |
| 292 |
|
| 293 |
- ansible.builtin.assert: |
| 294 |
that: |
| 295 |
- vol_attach_info.volumes[0].attachment_set[0].status in ['attached', 'attaching'] |
| 296 |
- vol_attach_info.volumes[0].attachment_set[0].instance_id == test_instance.instance_ids[0] |
| 297 |
- vol_attach_info.volumes[0].attachment_set[0].device == '/dev/sdg' |
| 298 |
- not vol_attach_info.volumes[0].attachment_set[0].delete_on_termination |
| 299 |
|
| 300 |
- name: Attach existing volume to an instance (idempotent - check_mode) |
| 301 |
amazon.aws.ec2_vol: |
| 302 |
id: "{{ volume1.volume_id }}" |
| 303 |
instance: "{{ test_instance.instance_ids[0] }}" |
| 304 |
device_name: /dev/sdg |
| 305 |
delete_on_termination: false |
| 306 |
check_mode: true |
| 307 |
register: vol_attach_result_check_mode |
| 308 |
|
| 309 |
- ansible.builtin.assert: |
| 310 |
that: |
| 311 |
- vol_attach_result_check_mode is not changed |
| 312 |
|
| 313 |
- name: Attach existing volume to an instance (idempotent) |
| 314 |
amazon.aws.ec2_vol: |
| 315 |
id: "{{ volume1.volume_id }}" |
| 316 |
instance: "{{ test_instance.instance_ids[0] }}" |
| 317 |
device_name: /dev/sdg |
| 318 |
delete_on_termination: false |
| 319 |
register: vol_attach_result |
| 320 |
|
| 321 |
- name: Check task return attributes |
| 322 |
ansible.builtin.assert: |
| 323 |
that: |
| 324 |
- not vol_attach_result.changed |
| 325 |
- vol_attach_result.volume.attachment_set[0].status in ['attached', 'attaching'] |
| 326 |
|
| 327 |
- name: Attach a new volume to an instance (check_mode) |
| 328 |
amazon.aws.ec2_vol: |
| 329 |
instance: "{{ test_instance.instance_ids[0] }}" |
| 330 |
device_name: /dev/sdh |
| 331 |
volume_size: 1 |
| 332 |
volume_type: gp2 |
| 333 |
name: "{{ resource_prefix }} - sdh" |
| 334 |
tags: |
| 335 |
lowercase spaced: hello cruel world |
| 336 |
Title Case: Hello Cruel World |
| 337 |
CamelCase: SimpleCamelCase |
| 338 |
snake_case: simple_snake_case |
| 339 |
ResourcePrefix: "{{ resource_prefix }}" |
| 340 |
check_mode: true |
| 341 |
register: new_vol_attach_result_check_mode |
| 342 |
|
| 343 |
- ansible.builtin.assert: |
| 344 |
that: |
| 345 |
- new_vol_attach_result_check_mode is changed |
| 346 |
|
| 347 |
- name: Attach a new volume to an instance |
| 348 |
amazon.aws.ec2_vol: |
| 349 |
instance: "{{ test_instance.instance_ids[0] }}" |
| 350 |
device_name: /dev/sdh |
| 351 |
volume_size: 1 |
| 352 |
volume_type: standard |
| 353 |
name: "{{ resource_prefix }} - sdh" |
| 354 |
tags: |
| 355 |
lowercase spaced: hello cruel world |
| 356 |
Title Case: Hello Cruel World |
| 357 |
CamelCase: SimpleCamelCase |
| 358 |
snake_case: simple_snake_case |
| 359 |
ResourcePrefix: "{{ resource_prefix }}" |
| 360 |
register: new_vol_attach_result |
| 361 |
|
| 362 |
- name: Check task return attributes |
| 363 |
ansible.builtin.assert: |
| 364 |
that: |
| 365 |
- new_vol_attach_result.changed |
| 366 |
- "'device' in new_vol_attach_result and new_vol_attach_result.device == '/dev/sdh'" |
| 367 |
- "'volume' in new_vol_attach_result" |
| 368 |
- new_vol_attach_result.volume.attachment_set[0].status in ['attached', 'attaching'] |
| 369 |
- new_vol_attach_result.volume.attachment_set[0].instance_id == test_instance.instance_ids[0] |
| 370 |
- new_vol_attach_result.volume.attachment_set[0].device == '/dev/sdh' |
| 371 |
- new_vol_attach_result.volume.tags["lowercase spaced"] == 'hello cruel world' |
| 372 |
- new_vol_attach_result.volume.tags["Title Case"] == 'Hello Cruel World' |
| 373 |
- new_vol_attach_result.volume.tags["CamelCase"] == 'SimpleCamelCase' |
| 374 |
- new_vol_attach_result.volume.tags["snake_case"] == 'simple_snake_case' |
| 375 |
- new_vol_attach_result.volume.tags["Name"] == resource_prefix +' - sdh' |
| 376 |
|
| 377 |
- name: Attach a new volume to an instance (idempotent - check_mode) |
| 378 |
amazon.aws.ec2_vol: |
| 379 |
instance: "{{ test_instance.instance_ids[0] }}" |
| 380 |
device_name: /dev/sdh |
| 381 |
volume_size: 1 |
| 382 |
volume_type: standard |
| 383 |
tags: |
| 384 |
ResourcePrefix: "{{ resource_prefix }}" |
| 385 |
check_mode: true |
| 386 |
register: new_vol_attach_result_idem_check_mode |
| 387 |
ignore_errors: true |
| 388 |
|
| 389 |
- ansible.builtin.assert: |
| 390 |
that: |
| 391 |
- new_vol_attach_result_idem_check_mode is not changed |
| 392 |
|
| 393 |
- name: Attach a new volume to an instance (idempotent) |
| 394 |
amazon.aws.ec2_vol: |
| 395 |
instance: "{{ test_instance.instance_ids[0] }}" |
| 396 |
device_name: /dev/sdh |
| 397 |
volume_size: 1 |
| 398 |
volume_type: standard |
| 399 |
tags: |
| 400 |
ResourcePrefix: "{{ resource_prefix }}" |
| 401 |
register: new_vol_attach_result_idem |
| 402 |
ignore_errors: true |
| 403 |
|
| 404 |
- name: Check task return attributes |
| 405 |
ansible.builtin.assert: |
| 406 |
that: |
| 407 |
- not new_vol_attach_result_idem.changed |
| 408 |
- "'Volume mapping for /dev/sdh already exists' in new_vol_attach_result_idem.msg" |
| 409 |
|
| 410 |
- name: Change some tag values |
| 411 |
amazon.aws.ec2_vol: |
| 412 |
instance: "{{ test_instance.instance_ids[0] }}" |
| 413 |
id: "{{ new_vol_attach_result.volume.id }}" |
| 414 |
device_name: /dev/sdh |
| 415 |
volume_size: 1 |
| 416 |
volume_type: standard |
| 417 |
tags: |
| 418 |
lowercase spaced: hello cruel world ❤️ |
| 419 |
Title Case: Hello Cruel World ❤️ |
| 420 |
CamelCase: SimpleCamelCase ❤️ |
| 421 |
snake_case: simple_snake_case ❤️ |
| 422 |
purge_tags: false |
| 423 |
register: new_vol_attach_result |
| 424 |
|
| 425 |
- name: Check task return attributes |
| 426 |
ansible.builtin.assert: |
| 427 |
that: |
| 428 |
- new_vol_attach_result.changed |
| 429 |
- "'volume_id' in new_vol_attach_result" |
| 430 |
- new_vol_attach_result.volume_id == new_vol_attach_result.volume_id |
| 431 |
- "'attachment_set' in new_vol_attach_result.volume" |
| 432 |
- "'create_time' in new_vol_attach_result.volume" |
| 433 |
- "'id' in new_vol_attach_result.volume" |
| 434 |
- "'size' in new_vol_attach_result.volume" |
| 435 |
- new_vol_attach_result.volume.size == 1 |
| 436 |
- "'volume_type' in new_vol_attach_result" |
| 437 |
- new_vol_attach_result.volume_type == 'standard' |
| 438 |
- "'tags' in new_vol_attach_result.volume" |
| 439 |
- (new_vol_attach_result.volume.tags | length) == 6 |
| 440 |
- new_vol_attach_result.volume.tags["lowercase spaced"] == 'hello cruel world ❤️' |
| 441 |
- new_vol_attach_result.volume.tags["Title Case"] == 'Hello Cruel World ❤️' |
| 442 |
- new_vol_attach_result.volume.tags["CamelCase"] == 'SimpleCamelCase ❤️' |
| 443 |
- new_vol_attach_result.volume.tags["snake_case"] == 'simple_snake_case ❤️' |
| 444 |
- new_vol_attach_result.volume.tags["ResourcePrefix"] == resource_prefix |
| 445 |
- new_vol_attach_result.volume.tags["Name"] == resource_prefix +' - sdh' |
| 446 |
|
| 447 |
- name: Change some tag values |
| 448 |
amazon.aws.ec2_vol: |
| 449 |
instance: "{{ test_instance.instance_ids[0] }}" |
| 450 |
id: "{{ new_vol_attach_result.volume.id }}" |
| 451 |
device_name: /dev/sdh |
| 452 |
volume_size: 1 |
| 453 |
volume_type: standard |
| 454 |
tags: |
| 455 |
lowercase spaced: hello cruel world ❤️ |
| 456 |
Title Case: Hello Cruel World ❤️ |
| 457 |
snake_case: simple_snake_case ❤️ |
| 458 |
ResourcePrefix: "{{ resource_prefix }}" |
| 459 |
purge_tags: true |
| 460 |
register: new_vol_attach_result |
| 461 |
|
| 462 |
- name: Check task return attributes |
| 463 |
ansible.builtin.assert: |
| 464 |
that: |
| 465 |
- new_vol_attach_result.changed |
| 466 |
- "'volume_id' in new_vol_attach_result" |
| 467 |
- new_vol_attach_result.volume_id == new_vol_attach_result.volume_id |
| 468 |
- "'attachment_set' in new_vol_attach_result.volume" |
| 469 |
- "'create_time' in new_vol_attach_result.volume" |
| 470 |
- "'id' in new_vol_attach_result.volume" |
| 471 |
- "'size' in new_vol_attach_result.volume" |
| 472 |
- new_vol_attach_result.volume.size == 1 |
| 473 |
- "'volume_type' in new_vol_attach_result" |
| 474 |
- new_vol_attach_result.volume_type == 'standard' |
| 475 |
- "'tags' in new_vol_attach_result.volume" |
| 476 |
- (new_vol_attach_result.volume.tags | length) == 4 |
| 477 |
- new_vol_attach_result.volume.tags["lowercase spaced"] == 'hello cruel world ❤️' |
| 478 |
- new_vol_attach_result.volume.tags["Title Case"] == 'Hello Cruel World ❤️' |
| 479 |
- new_vol_attach_result.volume.tags["snake_case"] == 'simple_snake_case ❤️' |
| 480 |
- new_vol_attach_result.volume.tags["ResourcePrefix"] == resource_prefix |
| 481 |
|
| 482 |
- name: Create a volume from a snapshot and attach to the instance (check_mode) |
| 483 |
amazon.aws.ec2_vol: |
| 484 |
instance: "{{ test_instance.instance_ids[0] }}" |
| 485 |
device_name: /dev/sdi |
| 486 |
snapshot: "{{ vol1_snapshot.snapshot_id }}" |
| 487 |
tags: |
| 488 |
ResourcePrefix: "{{ resource_prefix }}" |
| 489 |
check_mode: true |
| 490 |
register: attach_new_vol_from_snapshot_result_check_mode |
| 491 |
|
| 492 |
- ansible.builtin.assert: |
| 493 |
that: |
| 494 |
- attach_new_vol_from_snapshot_result_check_mode is changed |
| 495 |
|
| 496 |
- name: Create a volume from a snapshot and attach to the instance |
| 497 |
amazon.aws.ec2_vol: |
| 498 |
instance: "{{ test_instance.instance_ids[0] }}" |
| 499 |
device_name: /dev/sdi |
| 500 |
snapshot: "{{ vol1_snapshot.snapshot_id }}" |
| 501 |
tags: |
| 502 |
ResourcePrefix: "{{ resource_prefix }}" |
| 503 |
register: attach_new_vol_from_snapshot_result |
| 504 |
|
| 505 |
- name: Check task return attributes |
| 506 |
ansible.builtin.assert: |
| 507 |
that: |
| 508 |
- attach_new_vol_from_snapshot_result.changed |
| 509 |
- "'device' in attach_new_vol_from_snapshot_result and attach_new_vol_from_snapshot_result.device == '/dev/sdi'" |
| 510 |
- "'volume' in attach_new_vol_from_snapshot_result" |
| 511 |
- attach_new_vol_from_snapshot_result.volume.attachment_set[0].status in ['attached', 'attaching'] |
| 512 |
- attach_new_vol_from_snapshot_result.volume.attachment_set[0].instance_id == test_instance.instance_ids[0] |
| 513 |
|
| 514 |
- name: Get info on ebs volumes |
| 515 |
amazon.aws.ec2_vol_info: |
| 516 |
register: ec2_vol_info |
| 517 |
|
| 518 |
- name: Check task return attributes |
| 519 |
ansible.builtin.assert: |
| 520 |
that: |
| 521 |
- not ec2_vol_info.failed |
| 522 |
|
| 523 |
- name: Get info on ebs volumes |
| 524 |
amazon.aws.ec2_vol_info: |
| 525 |
filters: |
| 526 |
attachment.instance-id: "{{ test_instance.instance_ids[0] }}" |
| 527 |
register: ec2_vol_info |
| 528 |
|
| 529 |
- name: Check task return attributes |
| 530 |
ansible.builtin.assert: |
| 531 |
that: |
| 532 |
- ec2_vol_info.volumes | length == 4 |
| 533 |
|
| 534 |
- name: Must not change because of missing parameter modify_volume |
| 535 |
amazon.aws.ec2_vol: |
| 536 |
id: "{{ new_vol_attach_result.volume_id }}" |
| 537 |
zone: "{{ availability_zone }}" |
| 538 |
volume_type: gp3 |
| 539 |
register: changed_gp3_volume |
| 540 |
|
| 541 |
- name: Volume must not changed |
| 542 |
ansible.builtin.assert: |
| 543 |
that: |
| 544 |
- not changed_gp3_volume.changed |
| 545 |
|
| 546 |
- name: Change existing volume to gp3 (check_mode) |
| 547 |
amazon.aws.ec2_vol: |
| 548 |
id: "{{ new_vol_attach_result.volume_id }}" |
| 549 |
zone: "{{ availability_zone }}" |
| 550 |
volume_type: gp3 |
| 551 |
modify_volume: true |
| 552 |
check_mode: true |
| 553 |
register: changed_gp3_volume_check_mode |
| 554 |
|
| 555 |
- ansible.builtin.assert: |
| 556 |
that: |
| 557 |
- changed_gp3_volume_check_mode is changed |
| 558 |
|
| 559 |
- name: Change existing volume to gp3 |
| 560 |
amazon.aws.ec2_vol: |
| 561 |
id: "{{ new_vol_attach_result.volume_id }}" |
| 562 |
zone: "{{ availability_zone }}" |
| 563 |
volume_type: gp3 |
| 564 |
modify_volume: true |
| 565 |
register: changed_gp3_volume |
| 566 |
|
| 567 |
- name: Check that volume_type has changed |
| 568 |
ansible.builtin.assert: |
| 569 |
that: |
| 570 |
- changed_gp3_volume.changed |
| 571 |
- "'volume_id' in changed_gp3_volume" |
| 572 |
- changed_gp3_volume.volume_id == new_vol_attach_result.volume_id |
| 573 |
- "'attachment_set' in changed_gp3_volume.volume" |
| 574 |
- "'create_time' in changed_gp3_volume.volume" |
| 575 |
- "'id' in changed_gp3_volume.volume" |
| 576 |
- "'size' in changed_gp3_volume.volume" |
| 577 |
- "'volume_type' in changed_gp3_volume" |
| 578 |
- changed_gp3_volume.volume_type == 'gp3' |
| 579 |
- "'iops' in changed_gp3_volume.volume" |
| 580 |
- changed_gp3_volume.volume.iops == 3000 |
| 581 |
# Ensure our tags are still here |
| 582 |
- "'tags' in changed_gp3_volume.volume" |
| 583 |
- (changed_gp3_volume.volume.tags | length) == 4 |
| 584 |
- new_vol_attach_result.volume.tags["lowercase spaced"] == 'hello cruel world ❤️' |
| 585 |
- new_vol_attach_result.volume.tags["Title Case"] == 'Hello Cruel World ❤️' |
| 586 |
- new_vol_attach_result.volume.tags["snake_case"] == 'simple_snake_case ❤️' |
| 587 |
- new_vol_attach_result.volume.tags["ResourcePrefix"] == resource_prefix |
| 588 |
|
| 589 |
- name: Volume must be from type gp3 (idempotent) |
| 590 |
amazon.aws.ec2_vol: |
| 591 |
id: "{{ new_vol_attach_result.volume_id }}" |
| 592 |
zone: "{{ availability_zone }}" |
| 593 |
volume_type: gp3 |
| 594 |
modify_volume: true |
| 595 |
register: changed_gp3_volume |
| 596 |
retries: 10 |
| 597 |
delay: 3 |
| 598 |
until: not changed_gp3_volume.failed |
| 599 |
# retry because ebs change is to slow |
| 600 |
|
| 601 |
- name: Must not changed (idempotent) |
| 602 |
ansible.builtin.assert: |
| 603 |
that: |
| 604 |
- not changed_gp3_volume.changed |
| 605 |
- "'volume_id' in changed_gp3_volume" |
| 606 |
- changed_gp3_volume.volume_id == new_vol_attach_result.volume_id |
| 607 |
- "'attachment_set' in changed_gp3_volume.volume" |
| 608 |
- "'create_time' in changed_gp3_volume.volume" |
| 609 |
- "'id' in changed_gp3_volume.volume" |
| 610 |
- "'size' in changed_gp3_volume.volume" |
| 611 |
- "'volume_type' in changed_gp3_volume" |
| 612 |
- changed_gp3_volume.volume_type == 'gp3' |
| 613 |
- "'iops' in changed_gp3_volume.volume" |
| 614 |
- changed_gp3_volume.volume.iops == 3000 |
| 615 |
- "'throughput' in changed_gp3_volume.volume" |
| 616 |
- "'tags' in changed_gp3_volume.volume" |
| 617 |
- (changed_gp3_volume.volume.tags | length) == 4 |
| 618 |
- new_vol_attach_result.volume.tags["lowercase spaced"] == 'hello cruel world ❤️' |
| 619 |
- new_vol_attach_result.volume.tags["Title Case"] == 'Hello Cruel World ❤️' |
| 620 |
- new_vol_attach_result.volume.tags["snake_case"] == 'simple_snake_case ❤️' |
| 621 |
- new_vol_attach_result.volume.tags["ResourcePrefix"] == resource_prefix |
| 622 |
|
| 623 |
- name: Re-read volume information to validate new volume_type |
| 624 |
amazon.aws.ec2_vol_info: |
| 625 |
filters: |
| 626 |
volume-id: "{{ changed_gp3_volume.volume_id }}" |
| 627 |
register: verify_gp3_change |
| 628 |
|
| 629 |
- name: Volume type must be gp3 |
| 630 |
ansible.builtin.assert: |
| 631 |
that: |
| 632 |
- v.type == 'gp3' |
| 633 |
vars: |
| 634 |
v: "{{ verify_gp3_change.volumes[0] }}" |
| 635 |
|
| 636 |
- name: Detach volume from the instance (check_mode) |
| 637 |
amazon.aws.ec2_vol: |
| 638 |
id: "{{ new_vol_attach_result.volume_id }}" |
| 639 |
instance: "" |
| 640 |
check_mode: true |
| 641 |
register: new_vol_attach_result_check_mode |
| 642 |
|
| 643 |
- ansible.builtin.assert: |
| 644 |
that: |
| 645 |
- new_vol_attach_result_check_mode is changed |
| 646 |
|
| 647 |
- name: Detach volume from the instance |
| 648 |
amazon.aws.ec2_vol: |
| 649 |
id: "{{ new_vol_attach_result.volume_id }}" |
| 650 |
instance: "" |
| 651 |
register: new_vol_attach_result |
| 652 |
|
| 653 |
- name: Check task return attributes |
| 654 |
ansible.builtin.assert: |
| 655 |
that: |
| 656 |
- new_vol_attach_result.changed |
| 657 |
- new_vol_attach_result.volume.status == 'available' |
| 658 |
|
| 659 |
- name: Detach volume from the instance (idempotent - check_mode) |
| 660 |
amazon.aws.ec2_vol: |
| 661 |
id: "{{ new_vol_attach_result.volume_id }}" |
| 662 |
instance: "" |
| 663 |
register: new_vol_attach_result_idem_check_mode |
| 664 |
|
| 665 |
- name: Check task return attributes |
| 666 |
ansible.builtin.assert: |
| 667 |
that: |
| 668 |
- not new_vol_attach_result_idem_check_mode.changed |
| 669 |
|
| 670 |
- name: Detach volume from the instance (idempotent) |
| 671 |
amazon.aws.ec2_vol: |
| 672 |
id: "{{ new_vol_attach_result.volume_id }}" |
| 673 |
instance: "" |
| 674 |
register: new_vol_attach_result_idem |
| 675 |
|
| 676 |
- name: Check task return attributes |
| 677 |
ansible.builtin.assert: |
| 678 |
that: |
| 679 |
- not new_vol_attach_result_idem.changed |
| 680 |
|
| 681 |
- name: Delete volume (check_mode) |
| 682 |
amazon.aws.ec2_vol: |
| 683 |
id: "{{ volume2.volume_id }}" |
| 684 |
state: absent |
| 685 |
check_mode: true |
| 686 |
register: delete_volume_result_check_mode |
| 687 |
|
| 688 |
- ansible.builtin.assert: |
| 689 |
that: |
| 690 |
- delete_volume_result_check_mode is changed |
| 691 |
|
| 692 |
- name: Delete volume |
| 693 |
amazon.aws.ec2_vol: |
| 694 |
id: "{{ volume2.volume_id }}" |
| 695 |
state: absent |
| 696 |
register: delete_volume_result |
| 697 |
|
| 698 |
- name: Check task return attributes |
| 699 |
ansible.builtin.assert: |
| 700 |
that: |
| 701 |
- delete_volume_result.changed |
| 702 |
|
| 703 |
- name: Delete volume (idempotent - check_mode) |
| 704 |
amazon.aws.ec2_vol: |
| 705 |
id: "{{ volume2.volume_id }}" |
| 706 |
state: absent |
| 707 |
check_mode: true |
| 708 |
register: delete_volume_result_check_mode |
| 709 |
|
| 710 |
- ansible.builtin.assert: |
| 711 |
that: |
| 712 |
- delete_volume_result_check_mode is not changed |
| 713 |
|
| 714 |
- name: Delete volume (idempotent) |
| 715 |
amazon.aws.ec2_vol: |
| 716 |
id: "{{ volume2.volume_id }}" |
| 717 |
state: absent |
| 718 |
register: delete_volume_result_idem |
| 719 |
|
| 720 |
- name: Check task return attributes |
| 721 |
ansible.builtin.assert: |
| 722 |
that: |
| 723 |
- not delete_volume_result_idem.changed |
| 724 |
|
| 725 |
# Originally from ec2_vol_info |
| 726 |
|
| 727 |
- name: Create test volume with Destroy on Terminate |
| 728 |
amazon.aws.ec2_vol: |
| 729 |
instance: "{{ test_instance.instance_ids[0] }}" |
| 730 |
volume_size: 4 |
| 731 |
name: "{{ resource_prefix }}_delete_on_terminate" |
| 732 |
device_name: /dev/sdj |
| 733 |
volume_type: io1 |
| 734 |
iops: 100 |
| 735 |
tags: |
| 736 |
Tag Name with Space-and-dash: Tag Value with Space-and-dash |
| 737 |
delete_on_termination: true |
| 738 |
register: dot_volume |
| 739 |
|
| 740 |
- name: Check task return attributes |
| 741 |
ansible.builtin.assert: |
| 742 |
that: |
| 743 |
- dot_volume.changed |
| 744 |
- "'attachment_set' in dot_volume.volume" |
| 745 |
- "'delete_on_termination' in dot_volume.volume.attachment_set[0]" |
| 746 |
- "'create_time' in dot_volume.volume" |
| 747 |
- "'id' in dot_volume.volume" |
| 748 |
- "'size' in dot_volume.volume" |
| 749 |
- dot_volume.volume.size == 4 |
| 750 |
- "'volume_type' in dot_volume" |
| 751 |
- dot_volume.volume_type == 'io1' |
| 752 |
- "'iops' in dot_volume.volume" |
| 753 |
- dot_volume.volume.iops == 100 |
| 754 |
- "'tags' in dot_volume.volume" |
| 755 |
- (dot_volume.volume.tags | length ) == 2 |
| 756 |
- dot_volume.volume.tags["Name"] == resource_prefix+"_delete_on_terminate" |
| 757 |
- dot_volume.volume.tags["Tag Name with Space-and-dash"] == 'Tag Value with Space-and-dash' |
| 758 |
|
| 759 |
- name: Gather volume info without any filters |
| 760 |
amazon.aws.ec2_vol_info: |
| 761 |
register: volume_info_wo_filters |
| 762 |
check_mode: false |
| 763 |
|
| 764 |
- name: Check if info are returned without filters |
| 765 |
ansible.builtin.assert: |
| 766 |
that: |
| 767 |
- volume_info_wo_filters.volumes is defined |
| 768 |
|
| 769 |
- name: Gather volume info |
| 770 |
amazon.aws.ec2_vol_info: |
| 771 |
filters: |
| 772 |
tag:Name: "{{ resource_prefix }}_delete_on_terminate" |
| 773 |
register: volume_info |
| 774 |
check_mode: false |
| 775 |
|
| 776 |
- name: Format check |
| 777 |
ansible.builtin.assert: |
| 778 |
that: |
| 779 |
- volume_info.volumes|length == 1 |
| 780 |
- v.attachment_set[0].attach_time is defined |
| 781 |
- v.attachment_set[0].device is defined and v.attachment_set[0].device == dot_volume.device |
| 782 |
- v.attachment_set[0].instance_id is defined and v.attachment_set[0].instance_id == test_instance.instance_ids[0] |
| 783 |
- v.attachment_set[0].status is defined and v.attachment_set[0].status == 'attached' |
| 784 |
- v.create_time is defined |
| 785 |
- v.encrypted is defined and v.encrypted == false |
| 786 |
- v.id is defined and v.id == dot_volume.volume_id |
| 787 |
- v.iops is defined and v.iops == 100 |
| 788 |
- v.region is defined and v.region == aws_region |
| 789 |
- v.size is defined and v.size == 4 |
| 790 |
- v.snapshot_id is defined and v.snapshot_id == '' |
| 791 |
- v.status is defined and v.status == 'in-use' |
| 792 |
- v.tags.Name is defined and v.tags.Name == resource_prefix + '_delete_on_terminate' |
| 793 |
- v.tags['Tag Name with Space-and-dash'] == 'Tag Value with Space-and-dash' |
| 794 |
- v.type is defined and v.type == 'io1' |
| 795 |
- v.zone is defined and v.zone == test_instance.instances[0].placement.availability_zone |
| 796 |
vars: |
| 797 |
v: "{{ volume_info.volumes[0] }}" |
| 798 |
|
| 799 |
- name: New format check |
| 800 |
ansible.builtin.assert: |
| 801 |
that: |
| 802 |
- v.attachment_set[0].delete_on_termination is defined |
| 803 |
vars: |
| 804 |
v: "{{ volume_info.volumes[0] }}" |
| 805 |
when: ansible_version.full is version('2.7', '>=') |
| 806 |
|
| 807 |
- name: Test create a new gp3 volume |
| 808 |
amazon.aws.ec2_vol: |
| 809 |
volume_size: 70 |
| 810 |
zone: "{{ availability_zone }}" |
| 811 |
volume_type: gp3 |
| 812 |
throughput: 130 |
| 813 |
iops: 3001 |
| 814 |
name: GP3-TEST-{{ resource_prefix }} |
| 815 |
tags: |
| 816 |
ResourcePrefix: "{{ resource_prefix }}" |
| 817 |
register: gp3_volume |
| 818 |
|
| 819 |
- name: Check that volume_type is gp3 |
| 820 |
ansible.builtin.assert: |
| 821 |
that: |
| 822 |
- gp3_volume.changed |
| 823 |
- "'attachment_set' in gp3_volume.volume" |
| 824 |
- "'create_time' in gp3_volume.volume" |
| 825 |
- "'id' in gp3_volume.volume" |
| 826 |
- "'size' in gp3_volume.volume" |
| 827 |
- gp3_volume.volume.size == 70 |
| 828 |
- "'volume_type' in gp3_volume" |
| 829 |
- gp3_volume.volume_type == 'gp3' |
| 830 |
- "'iops' in gp3_volume.volume" |
| 831 |
- gp3_volume.volume.iops == 3001 |
| 832 |
- "'throughput' in gp3_volume.volume" |
| 833 |
- gp3_volume.volume.throughput == 130 |
| 834 |
- "'tags' in gp3_volume.volume" |
| 835 |
- (gp3_volume.volume.tags | length ) == 2 |
| 836 |
- gp3_volume.volume.tags["ResourcePrefix"] == resource_prefix |
| 837 |
|
| 838 |
- name: Read volume information to validate throughput |
| 839 |
amazon.aws.ec2_vol_info: |
| 840 |
filters: |
| 841 |
volume-id: "{{ gp3_volume.volume_id }}" |
| 842 |
register: verify_throughput |
| 843 |
|
| 844 |
- name: Throughput must be equal to 130 |
| 845 |
ansible.builtin.assert: |
| 846 |
that: |
| 847 |
- v.throughput == 130 |
| 848 |
vars: |
| 849 |
v: "{{ verify_throughput.volumes[0] }}" |
| 850 |
|
| 851 |
- name: Print out facts |
| 852 |
ansible.builtin.debug: |
| 853 |
var: vol_facts |
| 854 |
|
| 855 |
- name: Read volume information to validate throughput |
| 856 |
amazon.aws.ec2_vol_info: |
| 857 |
filters: |
| 858 |
volume-id: "{{ gp3_volume.volume_id }}" |
| 859 |
register: verify_throughput |
| 860 |
|
| 861 |
- name: Throughput must be equal to 130 |
| 862 |
ansible.builtin.assert: |
| 863 |
that: |
| 864 |
- v.throughput == 130 |
| 865 |
vars: |
| 866 |
v: "{{ verify_throughput.volumes[0] }}" |
| 867 |
|
| 868 |
- name: Print out facts |
| 869 |
ansible.builtin.debug: |
| 870 |
var: vol_facts |
| 871 |
|
| 872 |
- name: Increase throughput |
| 873 |
amazon.aws.ec2_vol: |
| 874 |
volume_size: 70 |
| 875 |
zone: "{{ availability_zone }}" |
| 876 |
volume_type: gp3 |
| 877 |
throughput: 131 |
| 878 |
modify_volume: true |
| 879 |
name: GP3-TEST-{{ resource_prefix }} |
| 880 |
tags: |
| 881 |
ResourcePrefix: "{{ resource_prefix }}" |
| 882 |
register: gp3_volume |
| 883 |
|
| 884 |
- name: Check that throughput has changed |
| 885 |
ansible.builtin.assert: |
| 886 |
that: |
| 887 |
- gp3_volume.changed |
| 888 |
- "'create_time' in gp3_volume.volume" |
| 889 |
- "'id' in gp3_volume.volume" |
| 890 |
- "'size' in gp3_volume.volume" |
| 891 |
- gp3_volume.volume.size == 70 |
| 892 |
- "'volume_type' in gp3_volume" |
| 893 |
- gp3_volume.volume_type == 'gp3' |
| 894 |
- "'iops' in gp3_volume.volume" |
| 895 |
- gp3_volume.volume.iops == 3001 |
| 896 |
- "'throughput' in gp3_volume.volume" |
| 897 |
- gp3_volume.volume.throughput == 131 |
| 898 |
|
| 899 |
# Multi-Attach disk |
| 900 |
- name: Create disk with multi-attach enabled |
| 901 |
amazon.aws.ec2_vol: |
| 902 |
volume_size: 4 |
| 903 |
volume_type: io1 |
| 904 |
iops: 102 |
| 905 |
zone: "{{ availability_zone }}" |
| 906 |
multi_attach: true |
| 907 |
tags: |
| 908 |
ResourcePrefix: "{{ resource_prefix }}" |
| 909 |
register: multi_attach_disk |
| 910 |
|
| 911 |
- name: Check volume creation |
| 912 |
ansible.builtin.assert: |
| 913 |
that: |
| 914 |
- multi_attach_disk.changed |
| 915 |
- "'volume' in multi_attach_disk" |
| 916 |
- multi_attach_disk.volume.multi_attach_enabled |
| 917 |
|
| 918 |
- name: Attach existing volume to an instance |
| 919 |
amazon.aws.ec2_vol: |
| 920 |
id: "{{ multi_attach_disk.volume_id }}" |
| 921 |
instance: "{{ test_instance.instance_ids[0] }}" |
| 922 |
device_name: /dev/sdk |
| 923 |
delete_on_termination: false |
| 924 |
register: vol_attach_result |
| 925 |
|
| 926 |
- name: Wait for instance to start |
| 927 |
amazon.aws.ec2_instance: |
| 928 |
state: running |
| 929 |
instance_ids: "{{ test_instance_2.instance_ids }}" |
| 930 |
wait: true |
| 931 |
|
| 932 |
- name: Attach existing volume to second instance |
| 933 |
amazon.aws.ec2_vol: |
| 934 |
id: "{{ multi_attach_disk.volume_id }}" |
| 935 |
instance: "{{ test_instance_2.instance_ids[0] }}" |
| 936 |
device_name: /dev/sdg |
| 937 |
delete_on_termination: false |
| 938 |
register: vol_attach_result |
| 939 |
|
| 940 |
- name: Check task return attributes |
| 941 |
ansible.builtin.assert: |
| 942 |
that: |
| 943 |
- vol_attach_result.changed |
| 944 |
- "'volume' in vol_attach_result" |
| 945 |
- vol_attach_result.volume.attachment_set | length == 2 |
| 946 |
- test_instance.instance_ids[0] in vol_attach_result.volume.attachment_set | map(attribute="instance_id") | list |
| 947 |
- test_instance_2.instance_ids[0] in vol_attach_result.volume.attachment_set | map(attribute="instance_id") | list |
| 948 |
|
| 949 |
- name: Create a volume without tags |
| 950 |
amazon.aws.ec2_vol: |
| 951 |
volume_size: 5 |
| 952 |
zone: "{{ availability_zone }}" |
| 953 |
instance: "{{ test_instance_3.instance_ids[0] }}" |
| 954 |
register: volume_without_tag |
| 955 |
|
| 956 |
- ansible.builtin.assert: |
| 957 |
that: |
| 958 |
- volume_without_tag.changed |
| 959 |
|
| 960 |
# idempotency check without tags |
| 961 |
- name: Create a volume without tags (idempotency check) |
| 962 |
amazon.aws.ec2_vol: |
| 963 |
volume_size: 5 |
| 964 |
zone: "{{ availability_zone }}" |
| 965 |
instance: "{{ test_instance_3.instance_ids[0] }}" |
| 966 |
register: volume_without_tag |
| 967 |
|
| 968 |
- ansible.builtin.assert: |
| 969 |
that: |
| 970 |
- not volume_without_tag.changed |
| 971 |
# ==== Cleanup ============================================================ |
| 972 |
|
| 973 |
always: |
| 974 |
- name: Describe the instance before we delete it |
| 975 |
amazon.aws.ec2_instance_info: |
| 976 |
instance_ids: |
| 977 |
- "{{ item }}" |
| 978 |
ignore_errors: true |
| 979 |
with_items: |
| 980 |
- "{{ test_instance.instance_ids[0] }}" |
| 981 |
- "{{ test_instance_2.instance_ids[0] }}" |
| 982 |
- "{{ test_instance_3.instance_ids[0] }}" |
| 983 |
register: pre_delete |
| 984 |
|
| 985 |
- ansible.builtin.debug: |
| 986 |
var: pre_delete |
| 987 |
|
| 988 |
- name: Delete test instance |
| 989 |
amazon.aws.ec2_instance: |
| 990 |
instance_ids: |
| 991 |
- "{{ item }}" |
| 992 |
state: terminated |
| 993 |
wait: true |
| 994 |
with_items: |
| 995 |
- "{{ test_instance.instance_ids[0] }}" |
| 996 |
- "{{ test_instance_2.instance_ids[0] }}" |
| 997 |
- "{{ test_instance_3.instance_ids[0] }}" |
| 998 |
ignore_errors: true |
| 999 |
|
| 1000 |
- name: Delete volumes |
| 1001 |
amazon.aws.ec2_vol: |
| 1002 |
id: "{{ item.volume_id }}" |
| 1003 |
state: absent |
| 1004 |
ignore_errors: true |
| 1005 |
with_items: |
| 1006 |
- "{{ volume1 }}" |
| 1007 |
- "{{ volume2 }}" |
| 1008 |
- "{{ volume3 }}" |
| 1009 |
- "{{ volume4 }}" |
| 1010 |
- "{{ new_vol_attach_result }}" |
| 1011 |
- "{{ attach_new_vol_from_snapshot_result }}" |
| 1012 |
- "{{ dot_volume }}" |
| 1013 |
- "{{ gp3_volume }}" |
| 1014 |
- "{{ multi_attach_disk }}" |
| 1015 |
- "{{ volume_without_tag }}" |
| 1016 |
|
| 1017 |
- name: Delete snapshot |
| 1018 |
amazon.aws.ec2_snapshot: |
| 1019 |
snapshot_id: "{{ vol1_snapshot.snapshot_id }}" |
| 1020 |
state: absent |
| 1021 |
ignore_errors: true |
| 1022 |
|
| 1023 |
- name: Delete test subnet |
| 1024 |
amazon.aws.ec2_vpc_subnet: |
| 1025 |
vpc_id: "{{ testing_vpc.vpc.id }}" |
| 1026 |
cidr: "{{ subnet_cidr }}" |
| 1027 |
state: absent |
| 1028 |
ignore_errors: true |
| 1029 |
|
| 1030 |
- name: Delete test VPC |
| 1031 |
amazon.aws.ec2_vpc_net: |
| 1032 |
name: "{{ vpc_name }}" |
| 1033 |
cidr_block: "{{ vpc_cidr }}" |
| 1034 |
state: absent |
| 1035 |
ignore_errors: true |