Skip to content

Commit 13fb638

Browse files
authored
refactor(ansible): bring our ansible up to modern ansible-lint standards (#1862)
1 parent 207b05f commit 13fb638

File tree

1 file changed

+83
-85
lines changed

1 file changed

+83
-85
lines changed

ansible/tasks/setup-wal-g.yml

Lines changed: 83 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,93 @@
1-
- name: Create wal-g group
2-
group:
3-
name: wal-g
4-
state: present
5-
when: nixpkg_mode
1+
- name: Execute wal-g things when nixpkg_mode
2+
when:
3+
- nixpkg_mode
4+
block:
5+
- name: Create wal-g group
6+
ansible.builtin.group:
7+
name: 'wal-g'
8+
state: 'present'
69

7-
- name: Create wal-g user
8-
user:
9-
name: wal-g
10-
shell: /bin/false
11-
comment: WAL-G user
12-
group: wal-g
13-
groups: wal-g, postgres
14-
when: nixpkg_mode
15-
- name: Create a config directory owned by wal-g
16-
file:
17-
path: /etc/wal-g
18-
state: directory
19-
owner: wal-g
20-
group: wal-g
21-
mode: '0770'
22-
when: nixpkg_mode
10+
- name: Create wal-g user
11+
ansible.builtin.user:
12+
comment: 'WAL-G user'
13+
group: 'wal-g'
14+
groups: 'wal-g, postgres'
15+
name: 'wal-g'
16+
shell: '/usr/bin/nologin'
17+
system: true
2318

24-
- name: Install wal-g 2 from nix binary cache
25-
become: yes
26-
shell: |
27-
sudo -u wal-g bash -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install github:supabase/postgres/{{ git_commit_sha }}#wal-g-2"
28-
when: stage2_nix
19+
- name: Create a config directory owned by wal-g
20+
ansible.builtin.file:
21+
group: 'wal-g'
22+
mode: '0770'
23+
owner: 'wal-g'
24+
path: '/etc/wal-g'
25+
state: 'directory'
2926

30-
- name: Install wal-g 3 from nix binary cache
31-
become: yes
32-
shell: |
33-
sudo -u wal-g bash -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install github:supabase/postgres/{{ git_commit_sha }}#wal-g-3"
34-
when: stage2_nix
27+
- name: Execute wal-g things when stage2_nix
28+
when:
29+
- stage2_nix
30+
block:
31+
- name: Install wal-g 2 from nix binary cache
32+
ansible.builtin.shell:
33+
cmd: sudo -u wal-g bash -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install github:supabase/postgres/{{ git_commit_sha }}#wal-g-2"
34+
become: true
3535

36-
- name: Create symlink for wal-g-3 from Nix profile to /usr/local/bin
37-
ansible.builtin.file:
38-
src: /home/wal-g/.nix-profile/bin/wal-g-3
39-
dest: /usr/local/bin/wal-g-v3
40-
state: link
41-
force: yes # This will replace existing file/symlink if it exists
42-
become: yes # Need sudo to write to /usr/local/bin
43-
when: stage2_nix
36+
- name: Install wal-g 3 from nix binary cache
37+
ansible.builtin.shell:
38+
cmd: sudo -u wal-g bash -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install github:supabase/postgres/{{ git_commit_sha }}#wal-g-3"
39+
become: true
4440

45-
- name: Create symlink to make wal-g-v2 the default wal-g
46-
ansible.builtin.file:
47-
src: /home/wal-g/.nix-profile/bin/wal-g-2
48-
dest: /usr/local/bin/wal-g
49-
state: link
50-
force: yes
51-
become: yes
52-
when: stage2_nix
41+
- name: Create symlink for wal-g-3 from Nix profile to /usr/local/bin
42+
ansible.builtin.file:
43+
dest: '/usr/local/bin/wal-g-v3'
44+
force: true
45+
src: '/home/wal-g/.nix-profile/bin/wal-g-3'
46+
state: 'link'
47+
become: true
5348

54-
- name: Create /etc/wal-g/config.json
55-
file:
56-
path: /etc/wal-g/config.json
57-
state: touch
58-
owner: wal-g
59-
group: wal-g
60-
mode: '0664'
61-
when: stage2_nix
49+
- name: Create symlink to make wal-g-v2 the default wal-g
50+
ansible.builtin.file:
51+
dest: '/usr/local/bin/wal-g'
52+
force: true
53+
src: '/home/wal-g/.nix-profile/bin/wal-g-2'
54+
state: 'link'
55+
become: true
6256

63-
- name: Move custom wal-g.conf file to /etc/postgresql-custom/wal-g.conf
64-
template:
65-
src: "files/postgresql_config/custom_walg.conf.j2"
66-
dest: /etc/postgresql-custom/wal-g.conf
67-
mode: 0664
68-
owner: postgres
69-
group: postgres
70-
when: stage2_nix
57+
- name: Create /etc/wal-g/config.json
58+
ansible.builtin.file:
59+
group: 'wal-g'
60+
mode: '0664'
61+
owner: 'wal-g'
62+
path: '/etc/wal-g/config.json'
63+
state: 'touch'
7164

72-
- name: Add script to be run for restore_command
73-
template:
74-
src: "files/walg_helper_scripts/wal_fetch.sh"
75-
dest: /home/postgres/wal_fetch.sh
76-
mode: 0500
77-
owner: postgres
78-
group: postgres
79-
when: stage2_nix
65+
- name: Move custom wal-g.conf file to /etc/postgresql-custom/wal-g.conf
66+
ansible.builtin.template:
67+
dest: '/etc/postgresql-custom/wal-g.conf'
68+
group: 'postgres'
69+
mode: '0664'
70+
owner: 'postgres'
71+
src: 'files/postgresql_config/custom_walg.conf.j2'
8072

81-
- name: Add helper script for wal_fetch.sh
82-
template:
83-
src: "files/walg_helper_scripts/wal_change_ownership.sh"
84-
dest: /root/wal_change_ownership.sh
85-
mode: 0700
86-
owner: root
87-
when: stage2_nix
73+
- name: Add script to be run for restore_command
74+
ansible.builtin.template:
75+
dest: '/home/postgres/wal_fetch.sh'
76+
group: 'postgres'
77+
mode: '0500'
78+
owner: 'postgres'
79+
src: 'files/walg_helper_scripts/wal_fetch.sh'
8880

89-
- name: Include /etc/postgresql-custom/wal-g.conf in postgresql.conf
90-
become: yes
91-
replace:
92-
path: /etc/postgresql/postgresql.conf
93-
regexp: "#include = '/etc/postgresql-custom/wal-g.conf'"
94-
replace: "include = '/etc/postgresql-custom/wal-g.conf'"
95-
when: stage2_nix
81+
- name: Add helper script for wal_fetch.sh
82+
ansible.builtin.template:
83+
dest: '/root/wal_change_ownership.sh'
84+
mode: '0700'
85+
owner: 'root'
86+
src: 'files/walg_helper_scripts/wal_change_ownership.sh'
87+
88+
- name: Include /etc/postgresql-custom/wal-g.conf in postgresql.conf
89+
ansible.builtin.replace:
90+
path: '/etc/postgresql/postgresql.conf'
91+
regexp: "#include = '/etc/postgresql-custom/wal-g.conf'"
92+
replace: "include = '/etc/postgresql-custom/wal-g.conf'"
93+
become: true

0 commit comments

Comments
 (0)