mirror of
https://github.com/ansible/awx-operator.git
synced 2026-03-26 21:33:14 +00:00
89 lines
2.4 KiB
YAML
89 lines
2.4 KiB
YAML
---
|
|
|
|
- name: Set variables from awxbackup object statuses if provided
|
|
block:
|
|
- name: Look up details for the backup object
|
|
k8s_info:
|
|
api_version: "{{ api_version }}"
|
|
kind: "AWXBackup"
|
|
name: "{{ backup }}"
|
|
namespace: "{{ backup_pvc_namespace }}"
|
|
register: this_backup
|
|
|
|
- name: Set backup pvc name from status
|
|
set_fact:
|
|
backup_pvc: "{{ this_backup['resources'][0]['status']['backupClaim'] }}"
|
|
|
|
- name: Set tmp backup directory from status
|
|
set_fact:
|
|
backup_dir: "{{ this_backup['resources'][0]['status']['backupDirectory'] }}"
|
|
when:
|
|
- backup != '' or backup is defined
|
|
|
|
# Check to make sure provided pvc exists, error loudly if not. Otherwise, the management pod will just stay in pending state forever.
|
|
- name: Check provided PVC exists
|
|
k8s_info:
|
|
name: "{{ backup_pvc }}"
|
|
kind: PersistentVolumeClaim
|
|
namespace: "{{ backup_pvc_namespace }}"
|
|
register: provided_pvc
|
|
when:
|
|
- backup_pvc != ''
|
|
|
|
- name: Surface error to user
|
|
block:
|
|
- name: Set error message
|
|
set_fact:
|
|
error_msg: "{{ backup_pvc }} does not exist, please create this pvc first."
|
|
|
|
- name: Handle error
|
|
import_tasks: error_handling.yml
|
|
|
|
- name: Fail early if pvc is defined but does not exist
|
|
fail:
|
|
msg: "{{ error_msg }}"
|
|
when:
|
|
- backup_pvc != ''
|
|
- provided_pvc.resources | length == 0
|
|
|
|
- name: Delete any existing management pod
|
|
k8s:
|
|
name: "{{ meta.name }}-db-management"
|
|
kind: Pod
|
|
namespace: "{{ backup_pvc_namespace }}"
|
|
state: absent
|
|
force: true
|
|
wait: true
|
|
|
|
- name: Create management pod from templated deployment config
|
|
k8s:
|
|
name: "{{ meta.name }}-db-management"
|
|
kind: Deployment
|
|
state: present
|
|
template: "management-pod.yml.j2"
|
|
wait: true
|
|
|
|
- name: Check to make sure backup directory exists on PVC
|
|
k8s_exec:
|
|
namespace: "{{ backup_pvc_namespace }}"
|
|
pod: "{{ meta.name }}-db-management"
|
|
command: >-
|
|
bash -c "stat {{ backup_dir }}"
|
|
register: stat_backup_dir
|
|
|
|
- name: Error if backup dir is missing
|
|
block:
|
|
- name: Set error message
|
|
set_fact:
|
|
error_msg: "{{ backup_dir }} does not exist, see the backupDirectory status on your AWXBackup for the correct backup_dir."
|
|
|
|
- name: Handle error
|
|
import_tasks: error_handling.yml
|
|
|
|
- name: Fail early if backup dir provided does not exist
|
|
fail:
|
|
msg: "{{ error_msg }}"
|
|
when:
|
|
- backup_dir != ''
|
|
- stat_backup_dir.return_code != 0
|