| 1 |
--- |
| 2 |
- name: 's3_lifecycle integration tests' |
| 3 |
collections: |
| 4 |
- amazon.aws |
| 5 |
module_defaults: |
| 6 |
group/aws: |
| 7 |
access_key: '{{ aws_access_key }}' |
| 8 |
secret_key: '{{ aws_secret_key }}' |
| 9 |
session_token: '{{ security_token | default(omit) }}' |
| 10 |
region: '{{ aws_region }}' |
| 11 |
s3_lifecycle: |
| 12 |
wait: true |
| 13 |
block: |
| 14 |
|
| 15 |
# ============================================================ |
| 16 |
- name: Create simple s3_bucket |
| 17 |
s3_bucket: |
| 18 |
name: '{{ bucket_name }}' |
| 19 |
state: present |
| 20 |
register: output |
| 21 |
|
| 22 |
- assert: |
| 23 |
that: |
| 24 |
- output.changed |
| 25 |
- output.name == bucket_name |
| 26 |
- not output.requester_pays |
| 27 |
# ============================================================ |
| 28 |
- name: Create a number of policies and check if all of them are created |
| 29 |
community.aws.s3_lifecycle: |
| 30 |
name: "{{ bucket_name }}" |
| 31 |
rule_id: "{{ item }}" |
| 32 |
expiration_days: 10 |
| 33 |
prefix: "{{ item }}" |
| 34 |
status: enabled |
| 35 |
state: present |
| 36 |
wait: true |
| 37 |
register: output |
| 38 |
loop: |
| 39 |
- rule_1 |
| 40 |
- rule_2 |
| 41 |
- rule_3 |
| 42 |
- assert: |
| 43 |
that: |
| 44 |
- (output.results | last).rules | length == 3 |
| 45 |
# ============================================================ |
| 46 |
- name: Remove previously created policies and check if all of them are removed |
| 47 |
community.aws.s3_lifecycle: |
| 48 |
name: "{{ bucket_name }}" |
| 49 |
rule_id: "{{ item }}" |
| 50 |
expiration_days: 10 |
| 51 |
prefix: "{{ item }}" |
| 52 |
status: enabled |
| 53 |
state: absent |
| 54 |
wait: true |
| 55 |
register: output |
| 56 |
loop: |
| 57 |
- rule_1 |
| 58 |
- rule_2 |
| 59 |
- rule_3 |
| 60 |
- assert: |
| 61 |
that: |
| 62 |
- (output.results | last).rules | length == 0 |
| 63 |
# ============================================================ |
| 64 |
- name: Create a lifecycle policy |
| 65 |
s3_lifecycle: |
| 66 |
name: '{{ bucket_name }}' |
| 67 |
expiration_days: 300 |
| 68 |
prefix: '' |
| 69 |
register: output |
| 70 |
|
| 71 |
- assert: |
| 72 |
that: |
| 73 |
- output is changed |
| 74 |
# ============================================================ |
| 75 |
- name: Create a lifecycle policy (idempotency) |
| 76 |
s3_lifecycle: |
| 77 |
name: '{{ bucket_name }}' |
| 78 |
expiration_days: 300 |
| 79 |
register: output |
| 80 |
|
| 81 |
- assert: |
| 82 |
that: |
| 83 |
- output is not changed |
| 84 |
# ============================================================ |
| 85 |
- name: Create a second lifecycle policy |
| 86 |
s3_lifecycle: |
| 87 |
name: '{{ bucket_name }}' |
| 88 |
transition_days: 30 |
| 89 |
prefix: /something |
| 90 |
register: output |
| 91 |
|
| 92 |
- assert: |
| 93 |
that: |
| 94 |
- output is changed |
| 95 |
# ============================================================ |
| 96 |
- name: Create a second lifecycle policy (idempotency) |
| 97 |
s3_lifecycle: |
| 98 |
name: '{{ bucket_name }}' |
| 99 |
transition_days: 30 |
| 100 |
prefix: /something |
| 101 |
register: output |
| 102 |
|
| 103 |
- assert: |
| 104 |
that: |
| 105 |
- output is not changed |
| 106 |
# ============================================================ |
| 107 |
- name: Disable the second lifecycle policy |
| 108 |
s3_lifecycle: |
| 109 |
name: '{{ bucket_name }}' |
| 110 |
status: disabled |
| 111 |
transition_days: 30 |
| 112 |
prefix: /something |
| 113 |
register: output |
| 114 |
|
| 115 |
- assert: |
| 116 |
that: |
| 117 |
- output is changed |
| 118 |
# ============================================================ |
| 119 |
- name: Disable the second lifecycle policy (idempotency) |
| 120 |
s3_lifecycle: |
| 121 |
name: '{{ bucket_name }}' |
| 122 |
status: disabled |
| 123 |
transition_days: 30 |
| 124 |
prefix: /something |
| 125 |
register: output |
| 126 |
|
| 127 |
- assert: |
| 128 |
that: |
| 129 |
- output is not changed |
| 130 |
# ============================================================ |
| 131 |
- name: Re-enable the second lifecycle policy |
| 132 |
s3_lifecycle: |
| 133 |
name: '{{ bucket_name }}' |
| 134 |
status: enabled |
| 135 |
transition_days: 300 |
| 136 |
prefix: /something |
| 137 |
register: output |
| 138 |
|
| 139 |
- assert: |
| 140 |
that: |
| 141 |
- output is changed |
| 142 |
# ============================================================ |
| 143 |
- name: Re-enable the second lifecycle policy (idempotency) |
| 144 |
s3_lifecycle: |
| 145 |
name: '{{ bucket_name }}' |
| 146 |
status: enabled |
| 147 |
transition_days: 300 |
| 148 |
prefix: /something |
| 149 |
register: output |
| 150 |
|
| 151 |
- assert: |
| 152 |
that: |
| 153 |
- output is not changed |
| 154 |
# ============================================================ |
| 155 |
- name: Delete the second lifecycle policy |
| 156 |
s3_lifecycle: |
| 157 |
name: '{{ bucket_name }}' |
| 158 |
state: absent |
| 159 |
prefix: /something |
| 160 |
register: output |
| 161 |
|
| 162 |
- assert: |
| 163 |
that: |
| 164 |
- output is changed |
| 165 |
# ============================================================ |
| 166 |
- name: Delete the second lifecycle policy (idempotency) |
| 167 |
s3_lifecycle: |
| 168 |
name: '{{ bucket_name }}' |
| 169 |
state: absent |
| 170 |
prefix: /something |
| 171 |
register: output |
| 172 |
|
| 173 |
- assert: |
| 174 |
that: |
| 175 |
- output is not changed |
| 176 |
# ============================================================ |
| 177 |
- name: Create a second lifecycle policy, with infrequent access |
| 178 |
s3_lifecycle: |
| 179 |
name: '{{ bucket_name }}' |
| 180 |
transition_days: 30 |
| 181 |
storage_class: standard_ia |
| 182 |
prefix: /something |
| 183 |
register: output |
| 184 |
|
| 185 |
- assert: |
| 186 |
that: |
| 187 |
- output is changed |
| 188 |
# ============================================================ |
| 189 |
- name: Create a second lifecycle policy, with infrequent access (idempotency) |
| 190 |
s3_lifecycle: |
| 191 |
name: '{{ bucket_name }}' |
| 192 |
storage_class: standard_ia |
| 193 |
transition_days: 30 |
| 194 |
prefix: /something |
| 195 |
register: output |
| 196 |
|
| 197 |
- assert: |
| 198 |
that: |
| 199 |
- output is not changed |
| 200 |
# ============================================================ |
| 201 |
- name: Create a second lifecycle policy, with glacier |
| 202 |
s3_lifecycle: |
| 203 |
name: '{{ bucket_name }}' |
| 204 |
transition_days: 300 |
| 205 |
prefix: /something |
| 206 |
register: output |
| 207 |
|
| 208 |
- assert: |
| 209 |
that: |
| 210 |
- output is changed |
| 211 |
# ============================================================ |
| 212 |
- name: Create a second lifecycle policy, with glacier (idempotency) |
| 213 |
s3_lifecycle: |
| 214 |
name: '{{ bucket_name }}' |
| 215 |
transition_days: 300 |
| 216 |
prefix: /something |
| 217 |
register: output |
| 218 |
|
| 219 |
- assert: |
| 220 |
that: |
| 221 |
- output is not changed |
| 222 |
# ============================================================ |
| 223 |
- name: Create a lifecycle policy, with glacier and transition_days to 0 |
| 224 |
s3_lifecycle: |
| 225 |
name: '{{ bucket_name }}' |
| 226 |
transition_days: 0 |
| 227 |
storage_class: glacier |
| 228 |
prefix: /something |
| 229 |
register: output |
| 230 |
|
| 231 |
- assert: |
| 232 |
that: |
| 233 |
- output is changed |
| 234 |
# ============================================================ |
| 235 |
- name: Create a lifecycle policy, with glacier and transition_days to 0 (idempotency) |
| 236 |
s3_lifecycle: |
| 237 |
name: '{{ bucket_name }}' |
| 238 |
transition_days: 0 |
| 239 |
storage_class: glacier |
| 240 |
prefix: /something |
| 241 |
register: output |
| 242 |
|
| 243 |
- assert: |
| 244 |
that: |
| 245 |
- output is not changed |
| 246 |
# ============================================================ |
| 247 |
- name: Create a lifecycle policy with infrequent access |
| 248 |
s3_lifecycle: |
| 249 |
name: '{{ bucket_name }}' |
| 250 |
transition_days: 30 |
| 251 |
storage_class: standard_ia |
| 252 |
prefix: /something |
| 253 |
register: output |
| 254 |
|
| 255 |
- name: Create a second lifecycle policy, with glacier |
| 256 |
s3_lifecycle: |
| 257 |
name: '{{ bucket_name }}' |
| 258 |
transition_days: 300 |
| 259 |
prefix: /something |
| 260 |
purge_transitions: false |
| 261 |
register: output |
| 262 |
|
| 263 |
- name: Create a lifecycle policy with infrequent access (idempotency) |
| 264 |
s3_lifecycle: |
| 265 |
name: '{{ bucket_name }}' |
| 266 |
storage_class: standard_ia |
| 267 |
transition_days: 30 |
| 268 |
prefix: /something |
| 269 |
purge_transitions: false |
| 270 |
register: output |
| 271 |
|
| 272 |
- assert: |
| 273 |
that: |
| 274 |
- output is not changed |
| 275 |
|
| 276 |
- name: Create a second lifecycle policy, with glacier (idempotency) |
| 277 |
s3_lifecycle: |
| 278 |
name: '{{ bucket_name }}' |
| 279 |
transition_days: 300 |
| 280 |
prefix: /something |
| 281 |
purge_transitions: false |
| 282 |
register: output |
| 283 |
|
| 284 |
- assert: |
| 285 |
that: |
| 286 |
- output is not changed |
| 287 |
# ============================================================ |
| 288 |
- name: Create a lifecycle policy, with noncurrent expiration |
| 289 |
s3_lifecycle: |
| 290 |
name: '{{ bucket_name }}' |
| 291 |
noncurrent_version_expiration_days: 300 |
| 292 |
prefix: /something |
| 293 |
register: output |
| 294 |
|
| 295 |
- assert: |
| 296 |
that: |
| 297 |
- output is changed |
| 298 |
# ============================================================ |
| 299 |
- name: Create a lifecycle policy, with noncurrent expiration |
| 300 |
s3_lifecycle: |
| 301 |
name: '{{ bucket_name }}' |
| 302 |
noncurrent_version_expiration_days: 300 |
| 303 |
prefix: /something |
| 304 |
register: output |
| 305 |
|
| 306 |
- assert: |
| 307 |
that: |
| 308 |
- output is not changed |
| 309 |
# ============================================================ |
| 310 |
- name: Create a lifecycle policy, with noncurrent transition |
| 311 |
s3_lifecycle: |
| 312 |
name: '{{ bucket_name }}' |
| 313 |
noncurrent_version_transition_days: 300 |
| 314 |
prefix: /something |
| 315 |
register: output |
| 316 |
|
| 317 |
- assert: |
| 318 |
that: |
| 319 |
- output is changed |
| 320 |
# ============================================================ |
| 321 |
- name: Create a lifecycle policy, with noncurrent transitions and expirations |
| 322 |
s3_lifecycle: |
| 323 |
name: '{{ bucket_name }}' |
| 324 |
noncurrent_version_transition_days: 300 |
| 325 |
prefix: /something |
| 326 |
register: output |
| 327 |
|
| 328 |
- assert: |
| 329 |
that: |
| 330 |
- output is not changed |
| 331 |
# ============================================================ |
| 332 |
- name: Create a lifecycle policy, with noncurrent transition |
| 333 |
s3_lifecycle: |
| 334 |
name: '{{ bucket_name }}' |
| 335 |
noncurrent_version_transition_days: 300 |
| 336 |
noncurrent_version_storage_class: standard_ia |
| 337 |
prefix: /something |
| 338 |
register: output |
| 339 |
|
| 340 |
- assert: |
| 341 |
that: |
| 342 |
- output is changed |
| 343 |
# ============================================================ |
| 344 |
- name: Create a lifecycle policy, with noncurrent transitions and expirations |
| 345 |
s3_lifecycle: |
| 346 |
name: '{{ bucket_name }}' |
| 347 |
noncurrent_version_storage_class: standard_ia |
| 348 |
noncurrent_version_transition_days: 300 |
| 349 |
prefix: /something |
| 350 |
register: output |
| 351 |
|
| 352 |
- assert: |
| 353 |
that: |
| 354 |
- output is not changed |
| 355 |
# ============================================================ |
| 356 |
- name: Create a lifecycle policy, with noncurrent transitions |
| 357 |
s3_lifecycle: |
| 358 |
name: '{{ bucket_name }}' |
| 359 |
noncurrent_version_transitions: |
| 360 |
- transition_days: 30 |
| 361 |
storage_class: standard_ia |
| 362 |
- transition_days: 60 |
| 363 |
storage_class: onezone_ia |
| 364 |
- transition_days: 90 |
| 365 |
storage_class: glacier |
| 366 |
prefix: /something |
| 367 |
register: output |
| 368 |
|
| 369 |
- assert: |
| 370 |
that: |
| 371 |
- output is changed |
| 372 |
# ============================================================ |
| 373 |
- name: Create a lifecycle policy, with noncurrent transitions |
| 374 |
s3_lifecycle: |
| 375 |
name: '{{ bucket_name }}' |
| 376 |
noncurrent_version_transitions: |
| 377 |
- transition_days: 30 |
| 378 |
storage_class: standard_ia |
| 379 |
- transition_days: 60 |
| 380 |
storage_class: onezone_ia |
| 381 |
- transition_days: 90 |
| 382 |
storage_class: glacier |
| 383 |
prefix: /something |
| 384 |
register: output |
| 385 |
|
| 386 |
- assert: |
| 387 |
that: |
| 388 |
- output is not changed |
| 389 |
|
| 390 |
# ============================================================ |
| 391 |
- name: Create a lifecycle policy, with abort_incomplete_multipart_upload |
| 392 |
s3_lifecycle: |
| 393 |
name: '{{ bucket_name }}' |
| 394 |
abort_incomplete_multipart_upload_days: 1 |
| 395 |
prefix: /something |
| 396 |
register: output |
| 397 |
|
| 398 |
- assert: |
| 399 |
that: |
| 400 |
- output is changed |
| 401 |
|
| 402 |
# ============================================================ |
| 403 |
- name: Create a lifecycle policy, with abort_incomplete_multipart_upload (idempotency) |
| 404 |
s3_lifecycle: |
| 405 |
name: '{{ bucket_name }}' |
| 406 |
abort_incomplete_multipart_upload_days: 1 |
| 407 |
prefix: /something |
| 408 |
register: output |
| 409 |
|
| 410 |
- assert: |
| 411 |
that: |
| 412 |
- output is not changed |
| 413 |
|
| 414 |
# ============================================================ |
| 415 |
- name: Create a lifecycle policy, with expired_object_delete_marker |
| 416 |
s3_lifecycle: |
| 417 |
name: '{{ bucket_name }}' |
| 418 |
expire_object_delete_marker: True |
| 419 |
prefix: /something |
| 420 |
register: output |
| 421 |
|
| 422 |
- assert: |
| 423 |
that: |
| 424 |
- output is changed |
| 425 |
|
| 426 |
- name: Create a lifecycle policy, with expired_object_delete_marker (idempotency) |
| 427 |
s3_lifecycle: |
| 428 |
name: '{{ bucket_name }}' |
| 429 |
expire_object_delete_marker: True |
| 430 |
prefix: /something |
| 431 |
register: output |
| 432 |
|
| 433 |
- assert: |
| 434 |
that: |
| 435 |
- output is not changed |
| 436 |
|
| 437 |
# ============================================================ |
| 438 |
- name: Update lifecycle policy, with noncurrent_version_expiration_days |
| 439 |
s3_lifecycle: |
| 440 |
name: '{{ bucket_name }}' |
| 441 |
noncurrent_version_expiration_days: 5 |
| 442 |
prefix: /something |
| 443 |
register: output |
| 444 |
|
| 445 |
- assert: |
| 446 |
that: |
| 447 |
- output is changed |
| 448 |
|
| 449 |
- name: Update lifecycle policy, with noncurrent_version_expiration_days (idempotency) |
| 450 |
s3_lifecycle: |
| 451 |
name: '{{ bucket_name }}' |
| 452 |
noncurrent_version_expiration_days: 5 |
| 453 |
prefix: /something |
| 454 |
register: output |
| 455 |
|
| 456 |
- assert: |
| 457 |
that: |
| 458 |
- output is not changed |
| 459 |
|
| 460 |
# ============================================================ |
| 461 |
- name: Update lifecycle policy, with noncurrent_version_keep_newer |
| 462 |
s3_lifecycle: |
| 463 |
name: '{{ bucket_name }}' |
| 464 |
noncurrent_version_expiration_days: 10 |
| 465 |
noncurrent_version_keep_newer: 6 |
| 466 |
prefix: /something |
| 467 |
register: output |
| 468 |
|
| 469 |
- assert: |
| 470 |
that: |
| 471 |
- output is changed |
| 472 |
|
| 473 |
- name: Update lifecycle policy, with noncurrent_version_keep_newer (idempotency) |
| 474 |
s3_lifecycle: |
| 475 |
name: '{{ bucket_name }}' |
| 476 |
noncurrent_version_expiration_days: 10 |
| 477 |
noncurrent_version_keep_newer: 6 |
| 478 |
prefix: /something |
| 479 |
register: output |
| 480 |
|
| 481 |
- assert: |
| 482 |
that: |
| 483 |
- output is not changed |
| 484 |
|
| 485 |
# ============================================================ |
| 486 |
# test all the examples |
| 487 |
# Configure a lifecycle rule on a bucket to expire (delete) items with a prefix of /logs/ after 30 days |
| 488 |
- name: example 1 |
| 489 |
s3_lifecycle: |
| 490 |
name: '{{ bucket_name }}' |
| 491 |
expiration_days: 30 |
| 492 |
prefix: /logs/ |
| 493 |
status: enabled |
| 494 |
state: present |
| 495 |
register: output |
| 496 |
- assert: |
| 497 |
that: |
| 498 |
- output is changed |
| 499 |
|
| 500 |
- name: example 1 (idempotency) |
| 501 |
s3_lifecycle: |
| 502 |
name: '{{ bucket_name }}' |
| 503 |
expiration_days: 30 |
| 504 |
prefix: /logs/ |
| 505 |
status: enabled |
| 506 |
state: present |
| 507 |
register: output |
| 508 |
- assert: |
| 509 |
that: |
| 510 |
- output is not changed |
| 511 |
|
| 512 |
# Configure a lifecycle rule to transition all items with a prefix of /logs/ to glacier after 7 days and then delete after 90 days |
| 513 |
- name: example 2 |
| 514 |
s3_lifecycle: |
| 515 |
name: '{{ bucket_name }}' |
| 516 |
transition_days: 7 |
| 517 |
expiration_days: 90 |
| 518 |
prefix: /logs/ |
| 519 |
status: enabled |
| 520 |
state: present |
| 521 |
register: output |
| 522 |
- assert: |
| 523 |
that: |
| 524 |
- output is changed |
| 525 |
|
| 526 |
- name: example 2 (idempotency) |
| 527 |
s3_lifecycle: |
| 528 |
name: '{{ bucket_name }}' |
| 529 |
transition_days: 7 |
| 530 |
expiration_days: 90 |
| 531 |
prefix: /logs/ |
| 532 |
status: enabled |
| 533 |
state: present |
| 534 |
register: output |
| 535 |
- assert: |
| 536 |
that: |
| 537 |
- output is not changed |
| 538 |
|
| 539 |
# Configure a lifecycle rule to transition all items with a prefix of /logs/ to glacier on 31 Dec 2020 and then delete on 31 Dec 2030. |
| 540 |
# Note that midnight GMT must be specified. |
| 541 |
# Be sure to quote your date strings |
| 542 |
- name: example 3 |
| 543 |
s3_lifecycle: |
| 544 |
name: '{{ bucket_name }}' |
| 545 |
transition_date: "2020-12-30T00:00:00.000Z" |
| 546 |
expiration_date: "2030-12-30T00:00:00.000Z" |
| 547 |
prefix: /logs/ |
| 548 |
status: enabled |
| 549 |
state: present |
| 550 |
register: output |
| 551 |
- assert: |
| 552 |
that: |
| 553 |
- output is changed |
| 554 |
|
| 555 |
- name: example 3 (idempotency) |
| 556 |
s3_lifecycle: |
| 557 |
name: '{{ bucket_name }}' |
| 558 |
transition_date: "2020-12-30T00:00:00.000Z" |
| 559 |
expiration_date: "2030-12-30T00:00:00.000Z" |
| 560 |
prefix: /logs/ |
| 561 |
status: enabled |
| 562 |
state: present |
| 563 |
register: output |
| 564 |
- assert: |
| 565 |
that: |
| 566 |
- output is not changed |
| 567 |
|
| 568 |
# Disable the rule created above |
| 569 |
- name: example 4 |
| 570 |
s3_lifecycle: |
| 571 |
name: '{{ bucket_name }}' |
| 572 |
prefix: /logs/ |
| 573 |
status: disabled |
| 574 |
state: present |
| 575 |
register: output |
| 576 |
- assert: |
| 577 |
that: |
| 578 |
- output is changed |
| 579 |
|
| 580 |
- name: example 4 (idempotency) |
| 581 |
s3_lifecycle: |
| 582 |
name: '{{ bucket_name }}' |
| 583 |
prefix: /logs/ |
| 584 |
status: disabled |
| 585 |
state: present |
| 586 |
register: output |
| 587 |
- assert: |
| 588 |
that: |
| 589 |
- output is not changed |
| 590 |
|
| 591 |
# Delete the lifecycle rule created above |
| 592 |
- name: example 5 |
| 593 |
s3_lifecycle: |
| 594 |
name: '{{ bucket_name }}' |
| 595 |
prefix: /logs/ |
| 596 |
state: absent |
| 597 |
register: output |
| 598 |
- assert: |
| 599 |
that: |
| 600 |
- output is changed |
| 601 |
|
| 602 |
- name: example 5 (idempotency) |
| 603 |
s3_lifecycle: |
| 604 |
name: '{{ bucket_name }}' |
| 605 |
prefix: /logs/ |
| 606 |
state: absent |
| 607 |
register: output |
| 608 |
- assert: |
| 609 |
that: |
| 610 |
- output is not changed |
| 611 |
|
| 612 |
# Configure a lifecycle rule to transition all backup files older than 31 days in /backups/ to standard infrequent access class. |
| 613 |
- name: example 6 |
| 614 |
s3_lifecycle: |
| 615 |
name: '{{ bucket_name }}' |
| 616 |
prefix: /backups/ |
| 617 |
storage_class: standard_ia |
| 618 |
transition_days: 31 |
| 619 |
state: present |
| 620 |
status: enabled |
| 621 |
register: output |
| 622 |
- assert: |
| 623 |
that: |
| 624 |
- output is changed |
| 625 |
|
| 626 |
- name: example 6 (idempotency) |
| 627 |
s3_lifecycle: |
| 628 |
name: '{{ bucket_name }}' |
| 629 |
prefix: /backups/ |
| 630 |
storage_class: standard_ia |
| 631 |
transition_days: 31 |
| 632 |
state: present |
| 633 |
status: enabled |
| 634 |
register: output |
| 635 |
- assert: |
| 636 |
that: |
| 637 |
- output is not changed |
| 638 |
|
| 639 |
# Configure a lifecycle rule to transition files to infrequent access after 30 days and glacier after 90 |
| 640 |
- name: example 7 |
| 641 |
s3_lifecycle: |
| 642 |
name: '{{ bucket_name }}' |
| 643 |
prefix: /other_logs/ |
| 644 |
state: present |
| 645 |
status: enabled |
| 646 |
transitions: |
| 647 |
- transition_days: 30 |
| 648 |
storage_class: standard_ia |
| 649 |
- transition_days: 90 |
| 650 |
storage_class: glacier |
| 651 |
register: output |
| 652 |
- assert: |
| 653 |
that: |
| 654 |
- output is changed |
| 655 |
|
| 656 |
- name: example 7 (idempotency) |
| 657 |
s3_lifecycle: |
| 658 |
name: '{{ bucket_name }}' |
| 659 |
prefix: /other_logs/ |
| 660 |
state: present |
| 661 |
status: enabled |
| 662 |
transitions: |
| 663 |
- transition_days: 30 |
| 664 |
storage_class: standard_ia |
| 665 |
- transition_days: 90 |
| 666 |
storage_class: glacier |
| 667 |
register: output |
| 668 |
- assert: |
| 669 |
that: |
| 670 |
- output is not changed |
| 671 |
|
| 672 |
# Check create and delete lifecycle policy with an empty prefix |
| 673 |
- name: Create rule with no prefix |
| 674 |
s3_lifecycle: |
| 675 |
name: "{{ bucket_name }}" |
| 676 |
rule_id: empty-prefix |
| 677 |
state: present |
| 678 |
status: enabled |
| 679 |
expiration_days: 30 |
| 680 |
register: output |
| 681 |
- assert: |
| 682 |
that: |
| 683 |
- output is changed |
| 684 |
|
| 685 |
- name: Delete rule with no prefix |
| 686 |
s3_lifecycle: |
| 687 |
name: "{{ bucket_name }}" |
| 688 |
rule_id: empty-prefix |
| 689 |
state: absent |
| 690 |
status: enabled |
| 691 |
expiration_days: 30 |
| 692 |
register: output |
| 693 |
- assert: |
| 694 |
that: |
| 695 |
- output is changed |
| 696 |
|
| 697 |
# Check create and delete lifecycle policy with minimum and maximum object size (with prefix) |
| 698 |
- name: Create rule with minimum and maximum object size |
| 699 |
s3_lifecycle: |
| 700 |
name: "{{ bucket_name }}" |
| 701 |
rule_id: minimum-object-size-prefix |
| 702 |
prefix: /something/ |
| 703 |
minimum_object_size: 100 |
| 704 |
maximum_object_size: 1000 |
| 705 |
state: present |
| 706 |
status: enabled |
| 707 |
expiration_days: 30 |
| 708 |
register: output |
| 709 |
- assert: |
| 710 |
that: |
| 711 |
- output is changed |
| 712 |
|
| 713 |
- name: Create rule with minimum object size (idempotency) |
| 714 |
s3_lifecycle: |
| 715 |
name: "{{ bucket_name }}" |
| 716 |
rule_id: minimum-object-size-prefix |
| 717 |
prefix: /something/ |
| 718 |
minimum_object_size: 100 |
| 719 |
maximum_object_size: 1000 |
| 720 |
state: present |
| 721 |
status: enabled |
| 722 |
expiration_days: 30 |
| 723 |
register: output |
| 724 |
- assert: |
| 725 |
that: |
| 726 |
- output is not changed |
| 727 |
|
| 728 |
- name: Delete rule with minimum and maximum object size |
| 729 |
s3_lifecycle: |
| 730 |
name: "{{ bucket_name }}" |
| 731 |
rule_id: minimum-object-size-prefix |
| 732 |
prefix: /something/ |
| 733 |
minimum_object_size: 100 |
| 734 |
maximum_object_size: 1000 |
| 735 |
state: absent |
| 736 |
status: enabled |
| 737 |
expiration_days: 30 |
| 738 |
register: output |
| 739 |
- assert: |
| 740 |
that: |
| 741 |
- output is changed |
| 742 |
|
| 743 |
# Check create and delete lifecycle policy with minimum and maximum object size (no prefix) |
| 744 |
- name: Create rule with minimum and maximum object size |
| 745 |
s3_lifecycle: |
| 746 |
name: "{{ bucket_name }}" |
| 747 |
rule_id: minimum-object-size-noprefix |
| 748 |
minimum_object_size: 100 |
| 749 |
maximum_object_size: 1000 |
| 750 |
state: present |
| 751 |
status: enabled |
| 752 |
expiration_days: 30 |
| 753 |
register: output |
| 754 |
- assert: |
| 755 |
that: |
| 756 |
- output is changed |
| 757 |
|
| 758 |
- name: Create rule with minimum object size (idempotency) |
| 759 |
s3_lifecycle: |
| 760 |
name: "{{ bucket_name }}" |
| 761 |
rule_id: minimum-object-size-noprefix |
| 762 |
minimum_object_size: 100 |
| 763 |
maximum_object_size: 1000 |
| 764 |
state: present |
| 765 |
status: enabled |
| 766 |
expiration_days: 30 |
| 767 |
register: output |
| 768 |
- assert: |
| 769 |
that: |
| 770 |
- output is not changed |
| 771 |
|
| 772 |
- name: Delete rule with minimum and maximum object size |
| 773 |
s3_lifecycle: |
| 774 |
name: "{{ bucket_name }}" |
| 775 |
rule_id: minimum-object-size-noprefix |
| 776 |
minimum_object_size: 100 |
| 777 |
maximum_object_size: 1000 |
| 778 |
state: absent |
| 779 |
status: enabled |
| 780 |
expiration_days: 30 |
| 781 |
register: output |
| 782 |
- assert: |
| 783 |
that: |
| 784 |
- output is changed |
| 785 |
|
| 786 |
# ============================================================ |
| 787 |
always: |
| 788 |
- name: Ensure all buckets are deleted |
| 789 |
s3_bucket: |
| 790 |
name: "{{item}}" |
| 791 |
state: absent |
| 792 |
ignore_errors: true |
| 793 |
with_items: |
| 794 |
- '{{ bucket_name }}' |