diff --git a/roles/installer/tasks/database_configuration.yml b/roles/installer/tasks/database_configuration.yml index 36987b57..3690ebc4 100644 --- a/roles/installer/tasks/database_configuration.yml +++ b/roles/installer/tasks/database_configuration.yml @@ -30,7 +30,6 @@ namespace: '{{ meta.namespace }}' name: '{{ meta.name }}-postgres-configuration' register: _generated_pg_config_resources - when: not _pg_config['resources'] | default([]) | length - name: Set PostgreSQL Configuration @@ -51,3 +50,8 @@ 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 + +- name: Migrate data from old Openshift instance + import_tasks: migrate_data.yml + when: tower_old_postgres_host is defined diff --git a/roles/installer/tasks/migrate_data.yml b/roles/installer/tasks/migrate_data.yml new file mode 100644 index 00000000..7805faeb --- /dev/null +++ b/roles/installer/tasks/migrate_data.yml @@ -0,0 +1,51 @@ +--- + +# - name: Use kubectl or oc +# set_fact: +# kubectl_or_oc: "{{ openshift_oc_bin if openshift_oc_bin is defined else 'kubectl' }}" + +# TODO: Either make everything below a block or included tasks +- name: Get Postgres container name + shell: | + oc -n {{ tower_namespace }} get pods -o jsonpath={.items[*].metadata.name} --selector app=tower-postgres + register: postgres_pod + +- name: oc exec command #TODO: Make this work with Kubectl too + set_fact: + container_exec: oc -n chadams-restore exec -i {{ postgres_pod.stdout }} -- bash -c + +# - name: Set psql command +# set_fact: +# psql_conn: 'psql -h {{ tower_old_postgres_host }} -U {{ tower_old_postgres_user }} -d {{ tower_old_postgres_database }} -p {{ tower_old_postgres_port }}' + +- name: Set pg_dump command + set_fact: + pgdump: | + pg_dump -h {{ tower_old_postgres_host }} \ + -U {{ tower_old_postgres_user }} \ + -d {{ tower_old_postgres_database }} \ + -p {{ tower_old_postgres_port }} + +- name: Set pg_restore command + set_fact: + psql_restore: | + psql \ + -U {{ awx_postgres_user }} \ + -d {{ awx_postgres_database }} \ + -p {{ awx_postgres_port }} + +- pause: + +- name: Set backup & restore command + set_fact: + psql_backup_restore: | + PGPASSWORD={{ tower_old_postgres_password }} {{ pgdump }} | PGPASSWORD={{ awx_postgres_pass }} {{ psql_restore }} + + # no_log: true #TODO uncomment + +- name: Migrate data from old postgresql if defined + shell: | + {{ container_exec }} '{{ psql_backup_restore }}' + # environment: + # PGPASSWORD: "{{ tower_old_postgres_password }}" + register: data_migration