From 5b89c5c433472a8c5393dd8de1ba118a5a55f874 Mon Sep 17 00:00:00 2001 From: "Christian M. Adams" Date: Mon, 15 Mar 2021 16:19:27 -0400 Subject: [PATCH] Clean db on Tower data is restored to --- roles/installer/tasks/database_configuration.yml | 11 +++++++++-- roles/installer/tasks/migrate_data.yml | 13 +++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/roles/installer/tasks/database_configuration.yml b/roles/installer/tasks/database_configuration.yml index 342dc8cd..9ba0fdff 100644 --- a/roles/installer/tasks/database_configuration.yml +++ b/roles/installer/tasks/database_configuration.yml @@ -6,6 +6,7 @@ name: '{{ tower_postgres_configuration_secret }}' register: _custom_pg_config_resources when: tower_postgres_configuration_secret | length + no_log: true - name: Check for default PostgreSQL configuration k8s_info: @@ -13,10 +14,12 @@ namespace: '{{ meta.namespace }}' name: '{{ meta.name }}-postgres-configuration' register: _default_pg_config_resources + no_log: true - name: Set PostgreSQL configuration set_fact: _pg_config: '{{ _custom_pg_config_resources["resources"] | default([]) | length | ternary(_custom_pg_config_resources, _default_pg_config_resources) }}' + no_log: true - block: - name: Create Database configuration @@ -31,10 +34,12 @@ name: '{{ meta.name }}-postgres-configuration' register: _generated_pg_config_resources when: not _pg_config['resources'] | default([]) | length + no_log: true - name: Set PostgreSQL Configuration set_fact: pg_config: '{{ _generated_pg_config_resources["resources"] | default([]) | length | ternary(_generated_pg_config_resources, _pg_config) }}' + no_log: true - name: Create Database if no database is specified k8s: @@ -42,6 +47,7 @@ definition: "{{ lookup('template', 'tower_postgres.yaml.j2') }}" when: - pg_config['resources'][0]['data']['type'] | default('') | b64decode == 'managed' + no_log: true - name: Store Database Configuration set_fact: @@ -50,7 +56,7 @@ 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 }}" - # no_log: true #TODO uncomment + no_log: true - name: Check for old PostgreSQL configuration secret k8s_info: @@ -59,8 +65,9 @@ name: '{{ tower_old_postgres_configuration_secret }}' register: old_pg_config when: tower_old_postgres_configuration_secret | length + no_log: true - name: Migrate data from old Openshift instance import_tasks: migrate_data.yml - when: old_pg_config['resources'][0]['data']['host'] is defined + when: old_pg_config['resources'][0]['data']['host'] is defined ignore_errors: true diff --git a/roles/installer/tasks/migrate_data.yml b/roles/installer/tasks/migrate_data.yml index d9845444..3894337c 100644 --- a/roles/installer/tasks/migrate_data.yml +++ b/roles/installer/tasks/migrate_data.yml @@ -7,6 +7,7 @@ tower_old_postgres_database: "{{ old_pg_config['resources'][0]['data']['database'] | b64decode }}" tower_old_postgres_port: "{{ old_pg_config['resources'][0]['data']['port'] | b64decode }}" tower_old_postgres_host: "{{ old_pg_config['resources'][0]['data']['host'] | b64decode }}" + no_log: true - name: Get the postgres pod information k8s_info: @@ -24,19 +25,22 @@ postgres_pod_name: "{{ postgres_pod['resources'][0]['metadata']['name'] }}" - name: Set pg_dump command - set_fact: + set_fact: pgdump: >- - pg_dump -h {{ tower_old_postgres_host }} + pg_dump --clean --create + -h {{ tower_old_postgres_host }} -U {{ tower_old_postgres_user }} -d {{ tower_old_postgres_database }} -p {{ tower_old_postgres_port }} + no_log: true - name: Set pg_restore command - set_fact: + set_fact: psql_restore: >- - psql -U {{ awx_postgres_user }} + psql -U {{ awx_postgres_user }} -d {{ awx_postgres_database }} -p {{ awx_postgres_port }} + no_log: true - name: Stream backup from pg_dump to the new postgresql container community.kubernetes.k8s_exec: @@ -44,6 +48,7 @@ pod: "{{ postgres_pod_name }}" command: >- bash -c "PGPASSWORD={{ tower_old_postgres_pass }} {{ pgdump }} | PGPASSWORD={{ awx_postgres_pass }} {{ psql_restore }}" + no_log: true ignore_errors: true register: data_migration # changed_when: success_condition?