Skip to content

Commit f0f2a64

Browse files
committed
refactor(ansible): bring our ansible up to modern ansible-lint standards
1 parent 7d2f6cb commit f0f2a64

File tree

1 file changed

+88
-78
lines changed

1 file changed

+88
-78
lines changed

ansible/tasks/test-image.yml

Lines changed: 88 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,97 @@
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
710

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'
2025

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+
regexp: "{{ regx }}"
29+
state: 'present'
30+
check_mode: true
31+
failed_when:
32+
- (pgconf is changed) or (pgconf is failed)
33+
loop:
34+
- "^shared_preload_libraries = '.*pgsodium.*'"
35+
- "^shared_preload_libraries = '.*supabase_vault.*'"
36+
- "^shared_preload_libraries = '.**supabase_vault.*'"
37+
- '^pgsodium\.getkey_script='
38+
loop_control:
39+
loop_var: 'regx'
40+
register: 'pgconf'
3541

3642
- name: Start Postgres Database to load all extensions.
37-
become: yes
38-
become_user: postgres
39-
shell:
43+
ansinle.builtin.command:
4044
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
4249

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'
5670

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
70-
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
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'
7780

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
81+
- name: Reset db stats
82+
community.postgresql.postgresql_query:
83+
login_db: 'postgres'
84+
login_host: 'localhost'
85+
login_user: 'supabase_admin'
86+
query: "{{ stat_item }}"
87+
loop:
88+
- 'SELECT pg_stat_statements_reset()'
89+
- 'SELECT pg_stat_reset()'
90+
loop_control:
91+
loop_var: 'stat_item'
8192

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
93+
- name: Restart Postgres Database in stage 2 to load all extensions
94+
ansible.builtin.command:
95+
cmd: "/usr/lib/postgresql/bin/pg_ctl --pgdata /var/lib/postgresql/data --mode fast --options '-c config_file=/etc/postgresql/postgresql.conf' stop
96+
become: true
97+
become_user: 'postgres'

0 commit comments

Comments
 (0)