|
497 | 497 | register: galerabackup_names |
498 | 498 | changed_when: false |
499 | 499 |
|
| 500 | + - name: Set GaleraBackup list |
| 501 | + ansible.builtin.set_fact: |
| 502 | + galerabackup_list: "{{ galerabackup_names.stdout.split() if galerabackup_names.stdout != '' else [] }}" |
| 503 | + |
500 | 504 | - name: Print GaleraBackup CRs found |
501 | 505 | ansible.builtin.debug: |
502 | | - msg: "GaleraBackup CRs: {{ galerabackup_names.stdout.split() if galerabackup_names.stdout != '' else 'none' }}" |
| 506 | + msg: "GaleraBackup CRs: {{ galerabackup_list if galerabackup_list | length > 0 else 'none' }}" |
| 507 | + |
| 508 | + - name: Render GaleraRestore CRs |
| 509 | + ansible.builtin.template: |
| 510 | + src: "{{ playbook_dir }}/templates/06a-galerarestore.yaml.j2" |
| 511 | + dest: "{{ rendered_dir.path }}/06a-galerarestore.yaml" |
| 512 | + when: galerabackup_list | length > 0 |
| 513 | + |
| 514 | + - name: "Next: Create GaleraRestore CRs" |
| 515 | + ansible.builtin.debug: |
| 516 | + msg: "{{ lookup('file', rendered_dir.path + '/06a-galerarestore.yaml').splitlines() }}" |
| 517 | + when: not (auto_ack | bool) and galerabackup_list | length > 0 |
503 | 518 |
|
504 | | - - name: Create GaleraRestore CRs |
| 519 | + - name: Apply GaleraRestore CRs |
505 | 520 | ansible.builtin.shell: | |
506 | | - BACKUP_NAME="{{ item }}" |
507 | | - RESTORE_NAME="${BACKUP_NAME}restore" |
508 | | - cat <<EOF | oc apply -f - |
509 | | - apiVersion: mariadb.openstack.org/v1beta1 |
510 | | - kind: GaleraRestore |
511 | | - metadata: |
512 | | - name: ${RESTORE_NAME} |
513 | | - namespace: {{ openstack_namespace }} |
514 | | - spec: |
515 | | - backupSource: ${BACKUP_NAME} |
516 | | - EOF |
517 | | - echo ${RESTORE_NAME} |
518 | | - loop: "{{ galerabackup_names.stdout.split() }}" |
519 | | - register: galerarestore_names |
| 521 | + oc apply -f {{ rendered_dir.path }}/06a-galerarestore.yaml |
| 522 | + register: galerarestore_apply |
520 | 523 | changed_when: true |
521 | | - when: galerabackup_names.stdout != "" |
| 524 | + when: galerabackup_list | length > 0 |
522 | 525 |
|
523 | 526 | - name: Wait for GaleraRestore pods to be ready |
524 | 527 | ansible.builtin.shell: | |
525 | | - RESTORE_NAME="{{ item.stdout_lines[-1] }}" |
526 | | - BACKUP_SOURCE=$(oc get galerarestore ${RESTORE_NAME} -n {{ openstack_namespace }} \ |
527 | | - -o jsonpath='{.spec.backupSource}') |
| 528 | + RESTORE_NAME="{{ item }}restore" |
| 529 | + BACKUP_SOURCE="{{ item }}" |
528 | 530 | POD_NAME="${BACKUP_SOURCE}-restore-${RESTORE_NAME}" |
529 | 531 | oc wait --for=condition=Ready pod/${POD_NAME} -n {{ openstack_namespace }} --timeout=120s |
530 | | - loop: "{{ galerarestore_names.results }}" |
| 532 | + loop: "{{ galerabackup_list }}" |
531 | 533 | changed_when: false |
532 | | - when: galerabackup_names.stdout != "" |
| 534 | + when: galerabackup_list | length > 0 |
533 | 535 |
|
534 | 536 | - name: Execute database restore for each GaleraRestore |
535 | 537 | ansible.builtin.shell: | |
536 | | - RESTORE_NAME="{{ item.stdout_lines[-1] }}" |
| 538 | + RESTORE_NAME="{{ item }}restore" |
537 | 539 | {{ playbook_dir }}/../scripts/restore-galera.sh ${RESTORE_NAME} {{ backup_timestamp }} {{ openstack_namespace }} |
538 | | - loop: "{{ galerarestore_names.results }}" |
| 540 | + loop: "{{ galerabackup_list }}" |
539 | 541 | changed_when: true |
540 | | - when: galerabackup_names.stdout != "" |
| 542 | + when: galerabackup_list | length > 0 |
541 | 543 |
|
542 | 544 | - name: Print Step 7 result |
543 | 545 | ansible.builtin.debug: |
544 | 546 | msg: "Database restore completed" |
545 | | - when: galerabackup_names.stdout != "" |
| 547 | + when: galerabackup_list | length > 0 |
546 | 548 |
|
547 | 549 | - name: Print Step 7 skip |
548 | 550 | ansible.builtin.debug: |
549 | 551 | msg: "No GaleraBackup CRs found - skipping database restore" |
550 | | - when: galerabackup_names.stdout == "" |
| 552 | + when: galerabackup_list | length == 0 |
551 | 553 |
|
552 | 554 | # ======================================== |
553 | 555 | # Step 8: Restore RabbitMQ Credentials |
|
0 commit comments