|
1 | | -# - name: Temporarily disable PG Sodium references in config |
2 | | -# become: yes |
3 | | -# become_user: postgres |
4 | | -# shell: |
5 | | -# cmd: sed -i.bak -e "s/pg_net,\ pgsodium,\ timescaledb/pg_net,\ timescaledb/g" -e "s/pgsodium.getkey_script=/#pgsodium.getkey_script=/g" /etc/postgresql/postgresql.conf |
6 | | -# when: debpkg_mode or stage2_nix |
| 1 | +- name: Execute tasks when (debpkg_mode or stage2_nix) |
| 2 | + when: |
| 3 | + - (debpkg_mode or stage2_nix) |
| 4 | + block: |
| 5 | + - name: Make a backup of the /etc/postgresql/postgresql.conf file |
| 6 | + ansible.builtin.copy: |
| 7 | + dest: '/etc/postgresql/postgresql.conf.bak' |
| 8 | + src: '/etc/postgresql/postgresql.conf' |
| 9 | + become: true |
7 | 10 |
|
8 | | -- name: Temporarily disable PG Sodium and Supabase Vault references in config |
9 | | - become: yes |
10 | | - become_user: postgres |
11 | | - shell: |
12 | | - cmd: > |
13 | | - sed -i.bak |
14 | | - -e 's/\(shared_preload_libraries = '\''.*\)pgsodium,\(.*'\''\)/\1\2/' |
15 | | - -e 's/\(shared_preload_libraries = '\''.*\)supabase_vault,\(.*'\''\)/\1\2/' |
16 | | - -e 's/\(shared_preload_libraries = '\''.*\), *supabase_vault'\''/\1'\''/' |
17 | | - -e 's/pgsodium.getkey_script=/#pgsodium.getkey_script=/' |
18 | | - /etc/postgresql/postgresql.conf |
19 | | - when: debpkg_mode or stage2_nix |
| 11 | + - name: Temporarily disable PG Sodium and Supabase Vault references in /etc/postgresql/postgresql.conf |
| 12 | + ansible.builtin.replace: |
| 13 | + path: '/etc/postgresql/postgresql.conf' |
| 14 | + regexp: "{{ regx['in'] }}" |
| 15 | + replace: "{{ regx['out'] }}" |
| 16 | + become: true |
| 17 | + become_user: 'postgres' |
| 18 | + loop: |
| 19 | + - { in: "^(shared_preload_libraries = '.*)pgsodium(.*')", out: '\1\2' } |
| 20 | + - { in: "^(shared_preload_libraries = '.*)supabase_vault(.*')", out: '\1\2' } |
| 21 | + - { in: "^(shared_preload_libraries = '.*)*supabase_vault(.*')", out: '\1\2' } |
| 22 | + - { in: '^(pgsodium\.getkey_script=)', out: '#\1' } |
| 23 | + loop_control: |
| 24 | + loop_var: 'regx' |
20 | 25 |
|
21 | | -- name: Verify pgsodium and vault removal from config |
22 | | - become: yes |
23 | | - become_user: postgres |
24 | | - shell: |
25 | | - cmd: | |
26 | | - FOUND=$(grep -E "shared_preload_libraries.*pgsodium|shared_preload_libraries.*supabase_vault|^pgsodium\.getkey_script" /etc/postgresql/postgresql.conf) |
27 | | - if [ ! -z "$FOUND" ]; then |
28 | | - echo "Found unremoved references:" |
29 | | - echo "$FOUND" |
30 | | - exit 1 |
31 | | - fi |
32 | | - register: verify_result |
33 | | - failed_when: verify_result.rc != 0 |
34 | | - when: debpkg_mode or stage2_nix |
| 26 | + - name: Make sure we disabled all the things |
| 27 | + ansible.builtin.lineinfile: |
| 28 | + path: '/etc/postgresql/postgresql.conf' |
| 29 | + regexp: "{{ regx }}" |
| 30 | + state: 'absent' |
| 31 | + check_mode: true |
| 32 | + failed_when: |
| 33 | + - (pgconf is changed) or (pgconf is failed) |
| 34 | + loop: |
| 35 | + - "^shared_preload_libraries = '.*pgsodium.*'" |
| 36 | + - "^shared_preload_libraries = '.*supabase_vault.*'" |
| 37 | + - '^pgsodium\.getkey_script=' |
| 38 | + loop_control: |
| 39 | + loop_var: 'regx' |
| 40 | + register: 'pgconf' |
35 | 41 |
|
36 | 42 | - name: Start Postgres Database to load all extensions. |
37 | | - become: yes |
38 | | - become_user: postgres |
39 | | - shell: |
| 43 | + ansible.builtin.command: |
40 | 44 | cmd: /usr/lib/postgresql/bin/pg_ctl -D /var/lib/postgresql/data start "-o -c config_file=/etc/postgresql/postgresql.conf" |
41 | | - when: debpkg_mode |
| 45 | + become: true |
| 46 | + become_user: 'postgres' |
| 47 | + when: |
| 48 | + - debpkg_mode |
42 | 49 |
|
43 | | -- name: Stop Postgres Database in stage 2 |
44 | | - become: yes |
45 | | - become_user: postgres |
46 | | - shell: source /var/lib/postgresql/.bashrc && /usr/lib/postgresql/bin/pg_ctl -D /var/lib/postgresql/data stop |
47 | | - args: |
48 | | - executable: /bin/bash |
49 | | - environment: |
50 | | - LANG: en_US.UTF-8 |
51 | | - LANGUAGE: en_US.UTF-8 |
52 | | - LC_ALL: en_US.UTF-8 |
53 | | - LC_CTYPE: en_US.UTF-8 |
54 | | - LOCALE_ARCHIVE: /usr/lib/locale/locale-archive |
55 | | - when: stage2_nix |
| 50 | +- name: Execute tasks when stage2_nix |
| 51 | + when: |
| 52 | + - stage2_nix |
| 53 | + block: |
| 54 | + - name: Restart Postgres Database in stage 2 to load all extensions |
| 55 | + ansible.builtin.command: |
| 56 | + cmd: "/usr/lib/postgresql/bin/pg_ctl --pgdata /var/lib/postgresql/data --mode fast --options '-c config_file=/etc/postgresql/postgresql.conf' {{ ctlcmd }}" |
| 57 | + become: true |
| 58 | + become_user: 'postgres' |
| 59 | + environment: |
| 60 | + LANG: 'en_US.UTF-8' |
| 61 | + LANGUAGE: 'en_US.UTF-8' |
| 62 | + LC_ALL: 'en_US.UTF-8' |
| 63 | + LC_CTYPE: 'en_US.UTF-8' |
| 64 | + LOCALE_ARCHIVE: '/usr/lib/locale/locale-archive' |
| 65 | + loop: |
| 66 | + - stop |
| 67 | + - start |
| 68 | + loop_control: |
| 69 | + loop_var: 'ctlcmd' |
56 | 70 |
|
57 | | -- name: Start Postgres Database to load all extensions. |
58 | | - become: yes |
59 | | - become_user: postgres |
60 | | - shell: source /var/lib/postgresql/.bashrc && /usr/lib/postgresql/bin/pg_ctl -D /var/lib/postgresql/data start "-o -c config_file=/etc/postgresql/postgresql.conf" |
61 | | - args: |
62 | | - executable: /bin/bash |
63 | | - environment: |
64 | | - LANG: en_US.UTF-8 |
65 | | - LANGUAGE: en_US.UTF-8 |
66 | | - LC_ALL: en_US.UTF-8 |
67 | | - LC_CTYPE: en_US.UTF-8 |
68 | | - LOCALE_ARCHIVE: /usr/lib/locale/locale-archive |
69 | | - when: stage2_nix |
| 71 | +- name: Execute tasks when (debpkg_mode or stage2_nix) |
| 72 | + when: |
| 73 | + - (debpkg_mode or stage2_nix) |
| 74 | + block: |
| 75 | + - name: Re-enable PG Sodium references in /etc/postgresql/postgresql.conf |
| 76 | + ansible.builtin.command: |
| 77 | + cmd: mv /etc/postgresql/postgresql.conf.bak /etc/postgresql/postgresql.conf |
| 78 | + become: true |
| 79 | + become_user: 'postgres' |
70 | 80 |
|
71 | | -- name: Re-enable PG Sodium references in config |
72 | | - become: yes |
73 | | - become_user: postgres |
74 | | - shell: |
75 | | - cmd: mv /etc/postgresql/postgresql.conf.bak /etc/postgresql/postgresql.conf |
76 | | - when: debpkg_mode or stage2_nix |
| 81 | + - name: Install psycopg2 |
| 82 | + ansible.builtin.apt: |
| 83 | + name: 'python3-psycopg2' |
| 84 | + state: 'present' |
| 85 | + update_cache: true |
| 86 | + become: true |
77 | 87 |
|
78 | | -- name: Reset db stats |
79 | | - shell: /usr/lib/postgresql/bin/psql --no-password --no-psqlrc -d postgres -h localhost -U supabase_admin -c 'SELECT pg_stat_statements_reset(); SELECT pg_stat_reset();' |
80 | | - when: debpkg_mode or stage2_nix |
| 88 | + - name: Reset db stats |
| 89 | + community.postgresql.postgresql_query: |
| 90 | + login_db: 'postgres' |
| 91 | + login_host: 'localhost' |
| 92 | + login_user: 'supabase_admin' |
| 93 | + query: "{{ stat_item }}" |
| 94 | + loop: |
| 95 | + # - 'SELECT pg_stat_statements_reset()' |
| 96 | + - 'SELECT pg_stat_reset()' |
| 97 | + loop_control: |
| 98 | + loop_var: 'stat_item' |
81 | 99 |
|
82 | | -- name: Stop Postgres Database |
83 | | - become: yes |
84 | | - become_user: postgres |
85 | | - shell: |
86 | | - cmd: /usr/lib/postgresql/bin/pg_ctl -D /var/lib/postgresql/data stop |
87 | | - when: debpkg_mode or stage2_nix |
| 100 | + - name: Restart Postgres Database in stage 2 to load all extensions |
| 101 | + ansible.builtin.command: |
| 102 | + cmd: /usr/lib/postgresql/bin/pg_ctl --pgdata /var/lib/postgresql/data --mode fast --options '-c config_file=/etc/postgresql/postgresql.conf' stop |
| 103 | + become: true |
| 104 | + become_user: 'postgres' |
0 commit comments