-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If pg_hostname is defined don't try to upgrade PostgreSQL
- Loading branch information
Showing
2 changed files
with
54 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- | ||
- name: Check for existing Postgres data | ||
stat: | ||
path: "{{ postgres_data_dir }}/pgdata/PG_VERSION" | ||
register: pg_version_file | ||
|
||
- name: Record Postgres version | ||
set_fact: | ||
old_pg_version: "{{ lookup('file', postgres_data_dir + '/pgdata/PG_VERSION') }}" | ||
when: pg_version_file.stat.exists | ||
|
||
- name: Determine whether to upgrade postgres | ||
set_fact: | ||
upgrade_postgres: "{{ old_pg_version is defined and old_pg_version == '9.6' }}" | ||
|
||
- name: Set up new postgres paths pre-upgrade | ||
file: | ||
state: directory | ||
path: "{{ item }}" | ||
recurse: true | ||
when: upgrade_postgres | bool | ||
with_items: | ||
- "{{ postgres_data_dir }}/10/data" | ||
|
||
- name: Stop AWX before upgrading postgres | ||
docker_service: | ||
project_src: "{{ docker_compose_dir }}" | ||
stopped: true | ||
when: upgrade_postgres | bool | ||
|
||
- name: Upgrade Postgres | ||
shell: | | ||
docker run --rm \ | ||
-v {{ postgres_data_dir }}/pgdata:/var/lib/postgresql/9.6/data \ | ||
-v {{ postgres_data_dir }}/10/data:/var/lib/postgresql/10/data \ | ||
-e PGUSER={{ pg_username }} -e POSTGRES_INITDB_ARGS="-U {{ pg_username }}" \ | ||
tianon/postgres-upgrade:9.6-to-10 --username={{ pg_username }} | ||
when: upgrade_postgres | bool | ||
|
||
- name: Copy old pg_hba.conf | ||
copy: | ||
src: "{{ postgres_data_dir + '/pgdata/pg_hba.conf' }}" | ||
dest: "{{ postgres_data_dir + '/10/data/' }}" | ||
when: upgrade_postgres | bool | ||
|
||
- name: Remove old data directory | ||
file: | ||
path: "{{ postgres_data_dir + '/pgdata' }}" | ||
state: absent | ||
when: compose_start_containers|bool |