mirror of
https://github.com/ansible/awx-operator.git
synced 2026-03-26 21:33:14 +00:00
95 lines
3.1 KiB
YAML
95 lines
3.1 KiB
YAML
---
|
|
|
|
- name: Check for specified PostgreSQL configuration
|
|
k8s_info:
|
|
kind: Secret
|
|
namespace: '{{ meta.namespace }}'
|
|
name: '{{ tower_postgres_configuration_secret }}'
|
|
register: _custom_pg_config_resources
|
|
when: tower_postgres_configuration_secret | length
|
|
|
|
- name: Check for default PostgreSQL configuration
|
|
k8s_info:
|
|
kind: Secret
|
|
namespace: '{{ meta.namespace }}'
|
|
name: '{{ tower_name }}-postgres-configuration'
|
|
register: _default_pg_config_resources
|
|
|
|
- name: Set PostgreSQL configuration
|
|
set_fact:
|
|
pg_config: '{{ _custom_pg_config_resources["resources"] | default([]) | length | ternary(_custom_pg_config_resources, _default_pg_config_resources) }}'
|
|
|
|
- name: Store Database Configuration
|
|
set_fact:
|
|
awx_postgres_user: "{{ pg_config['resources'][0]['data']['username'] | b64decode }}"
|
|
awx_postgres_pass: "{{ pg_config['resources'][0]['data']['password'] | b64decode }}"
|
|
awx_postgres_database: "{{ pg_config['resources'][0]['data']['database'] | b64decode }}"
|
|
awx_postgres_port: "{{ pg_config['resources'][0]['data']['port'] | b64decode }}"
|
|
awx_postgres_host: "{{ pg_config['resources'][0]['data']['host'] | b64decode }}"
|
|
|
|
- name: Default label selector to custom resource generated postgres
|
|
set_fact:
|
|
postgres_label_selector: "app.kubernetes.io/name={{ meta.name }}-postgres"
|
|
when: postgres_label_selector is not defined
|
|
|
|
- name: Get the postgres pod information
|
|
k8s_info:
|
|
kind: Pod
|
|
namespace: '{{ meta.namespace }}'
|
|
label_selectors:
|
|
- "{{ postgres_label_selector }}"
|
|
register: postgres_pod
|
|
until:
|
|
- "postgres_pod['resources'] | length"
|
|
- "postgres_pod['resources'][0]['status']['phase'] == 'Running'"
|
|
delay: 5
|
|
retries: 60
|
|
|
|
- name: Set the resource pod name as a variable.
|
|
set_fact:
|
|
postgres_pod_name: "{{ postgres_pod['resources'][0]['metadata']['name'] }}"
|
|
|
|
- name: Check for presence of AWX Deployment
|
|
k8s_info:
|
|
api_version: v1
|
|
kind: Deployment
|
|
name: "{{ meta.name }}"
|
|
namespace: "{{ meta.namespace }}"
|
|
register: this_deployment
|
|
|
|
- name: Scale down Deployment for migration
|
|
k8s_scale:
|
|
api_version: v1
|
|
kind: Deployment
|
|
name: "{{ meta.name }}"
|
|
namespace: "{{ meta.namespace }}"
|
|
replicas: 0
|
|
when: this_deployment['resources'] | length
|
|
|
|
- name: Set full resolvable host name for postgres pod
|
|
set_fact:
|
|
resolvable_db_host: "{{ awx_postgres_host }}.{{ meta.namespace }}.svc.cluster.local"
|
|
when: awx_postgres_type == 'managed'
|
|
|
|
- name: Set pg_restore command
|
|
set_fact:
|
|
psql_restore: >-
|
|
psql -U {{ awx_postgres_user }}
|
|
-h {{ resolvable_db_host }}
|
|
-U {{ awx_postgres_user }}
|
|
-d {{ awx_postgres_database }}
|
|
-p {{ awx_postgres_port }}
|
|
|
|
- name: Restore database dump to the new postgresql container
|
|
k8s_exec:
|
|
namespace: "{{ tower_backup_pvc_namespace }}"
|
|
pod: "{{ meta.name }}-db-management"
|
|
command: |
|
|
bash -c """
|
|
set -e -o pipefail
|
|
cat {{ tower_backup_dir }}/tower.db | PGPASSWORD={{ awx_postgres_pass }} {{ psql_restore }}
|
|
echo 'Successful'
|
|
"""
|
|
register: data_migration
|
|
failed_when: "'Successful' not in data_migration.stdout"
|