Skip to content

Commit 65939d6

Browse files
authored
Install WAL-G from the binary file (#768)
1 parent 0b47be0 commit 65939d6

File tree

2 files changed

+59
-14
lines changed

2 files changed

+59
-14
lines changed

automation/roles/wal-g/tasks/main.yml

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
- wal_g_auto_conf | default(true) | bool # to be able to disable auto backup settings
99
tags: wal-g, wal_g, wal_g_conf
1010

11+
# Pre-check
1112
- name: Check if WAL-G is already installed
1213
ansible.builtin.shell: |
1314
set -o pipefail;
14-
"{{ wal_g_path }}" --version | awk {'print $3'} | tr -d 'v'
15+
"{{ wal_g_path.split(' ')[0] }}" --version | awk {'print $3'} | tr -d 'v'
1516
args:
1617
executable: /bin/bash
1718
changed_when: false
@@ -29,7 +30,48 @@
2930
- wal_g_installed_version.stdout == wal_g_version
3031
tags: wal-g, wal_g, wal_g_install
3132

32-
# Build WAL-G from source code for other Linux distributions
33+
# Install WAL-G from a precompiled binary
34+
# (if 'wal_g_installation_method' is 'binary')
35+
# Note: excluding RHEL 8 as GLIBC version 2.29 or higher is required.
36+
- block:
37+
- name: "Download WAL-G v{{ wal_g_version | replace('v', '') }} binary"
38+
ansible.builtin.get_url:
39+
url: "{{ wal_g_repo }}/{{ wal_g_archive }}"
40+
dest: /tmp/
41+
timeout: 60
42+
validate_certs: false
43+
vars:
44+
wal_g_repo: "https://github.com/wal-g/wal-g/releases/download/v{{ wal_g_version | replace('v', '') }}"
45+
wal_g_archive: "wal-g-pg-ubuntu-20.04-amd64.tar.gz"
46+
environment: "{{ proxy_env | default({}) }}"
47+
48+
# Note: We are using a precompiled binary on Ubuntu 20.04,
49+
# but since Go binaries are cross-platform, it works well on other distributions as well.
50+
51+
- name: Extract WAL-G into /tmp
52+
ansible.builtin.unarchive:
53+
src: "/tmp/wal-g-pg-ubuntu-20.04-amd64.tar.gz"
54+
dest: /tmp/
55+
extra_opts:
56+
- --no-same-owner
57+
remote_src: true
58+
59+
- name: Copy WAL-G binary file to "{{ wal_g_path.split(' ')[0] }}"
60+
ansible.builtin.copy:
61+
src: "/tmp/wal-g-pg-ubuntu-20.04-amd64"
62+
dest: "{{ wal_g_path.split(' ')[0] }}"
63+
mode: u+x,g+x,o+x
64+
remote_src: true
65+
when:
66+
- installation_method == "repo"
67+
- wal_g_installation_method == "binary"
68+
- wal_g_version is version('1.0', '>=')
69+
- (wal_g_installed_version.stderr is search("command not found") or wal_g_installed_version.stdout != wal_g_version)
70+
- not (ansible_os_family == "RedHat" and ansible_distribution_major_version == '8')
71+
tags: wal-g, wal_g, wal_g_install
72+
73+
# Install WAL-G from the source code
74+
# (if 'wal_g_installation_method' is 'src')
3375
- block:
3476
- name: Install lib dependencies to build WAL-G
3577
ansible.builtin.package:
@@ -103,11 +145,12 @@
103145
when: go_installed_version.stderr is search("command not found") or
104146
go_installed_version.stdout is version(wal_g_latest_version.stdout, '<')
105147

106-
- name: "Download WAL-G v{{ wal_g_version }} source code"
148+
- name: "Download WAL-G v{{ wal_g_version | replace('v', '') }} source code"
107149
ansible.builtin.git:
108150
repo: https://github.com/wal-g/wal-g.git
109-
version: v{{ wal_g_version }}
151+
version: v{{ wal_g_version | replace('v', '') }}
110152
dest: /tmp/wal-g
153+
force: true
111154

112155
- name: Run go mod tidy to ensure dependencies are correct
113156
ansible.builtin.command: go mod tidy
@@ -145,15 +188,16 @@
145188
environment: "{{ proxy_env | default({}) }}"
146189
when:
147190
- installation_method == "repo"
191+
- (wal_g_installation_method == "src" or (ansible_os_family == "RedHat" and ansible_distribution_major_version == '8'))
148192
- wal_g_version is version('1.0', '>=')
149193
- (wal_g_installed_version.stderr is search("command not found") or wal_g_installed_version.stdout != wal_g_version)
150194
tags: wal-g, wal_g, wal_g_install
151195

152196
# older versions of WAL-G (for compatibility)
153197
- block:
154-
- name: "Download WAL-G v{{ wal_g_version }} binary"
198+
- name: "Download WAL-G v{{ wal_g_version | replace('v', '') }} binary"
155199
ansible.builtin.get_url:
156-
url: "https://github.com/wal-g/wal-g/releases/download/v{{ wal_g_version }}/wal-g.linux-amd64.tar.gz"
200+
url: "https://github.com/wal-g/wal-g/releases/download/v{{ wal_g_version | replace('v', '') }}/wal-g.linux-amd64.tar.gz"
157201
dest: /tmp/
158202
timeout: 60
159203
validate_certs: false
@@ -167,17 +211,17 @@
167211
- --no-same-owner
168212
remote_src: true
169213

170-
- name: Copy WAL-G binary file to "{{ wal_g_path }}"
214+
- name: Copy WAL-G binary file to "{{ wal_g_path.split(' ')[0] }}"
171215
ansible.builtin.copy:
172216
src: "/tmp/wal-g"
173-
dest: "{{ wal_g_path }}"
217+
dest: "{{ wal_g_path.split(' ')[0] }}"
174218
mode: u+x,g+x,o+x
175219
remote_src: true
176220
when:
177221
- installation_method == "repo"
222+
- wal_g_installation_method == "binary"
178223
- wal_g_version is version('0.2.19', '<=')
179-
- (wal_g_installed_version.stderr is search("command not found") or
180-
wal_g_installed_version.stdout != wal_g_version)
224+
- (wal_g_installed_version.stderr is search("command not found") or wal_g_installed_version.stdout != wal_g_version)
181225
tags: wal-g, wal_g, wal_g_install
182226

183227
# installation_method == "file"
@@ -191,10 +235,10 @@
191235
extra_opts:
192236
- --no-same-owner
193237

194-
- name: Copy WAL-G binary file to "{{ wal_g_path }}"
238+
- name: Copy WAL-G binary file to "{{ wal_g_path.split(' ')[0] }}"
195239
ansible.builtin.copy:
196240
src: "/tmp/{{ wal_g_package_file.split('.tar.gz')[0] | basename }}"
197-
dest: "{{ wal_g_path }}"
241+
dest: "{{ wal_g_path.split(' ')[0] }}"
198242
mode: u+x,g+x,o+x
199243
remote_src: true
200244
when:
@@ -214,10 +258,10 @@
214258
extra_opts:
215259
- --no-same-owner
216260

217-
- name: Copy WAL-G binary file to "{{ wal_g_path }}"
261+
- name: Copy WAL-G binary file to "{{ wal_g_path.split(' ')[0] }}"
218262
ansible.builtin.copy:
219263
src: "/tmp/wal-g"
220-
dest: "{{ wal_g_path }}"
264+
dest: "{{ wal_g_path.split(' ')[0] }}"
221265
mode: u+x,g+x,o+x
222266
remote_src: true
223267
when:

automation/vars/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ pg_probackup_patroni_cluster_bootstrap_command: "{{ pg_probackup_command_parts |
504504
# WAL-G
505505
wal_g_install: false # or 'true'
506506
wal_g_version: "3.0.3"
507+
wal_g_installation_method: "binary" # or "src" to build from source code
507508
wal_g_path: "/usr/local/bin/wal-g --config {{ postgresql_home_dir }}/.walg.json"
508509
wal_g_json: # config https://github.com/wal-g/wal-g#configuration
509510
- { option: "AWS_ACCESS_KEY_ID", value: "{{ AWS_ACCESS_KEY_ID | default('') }}" } # define values or pass via --extra-vars

0 commit comments

Comments
 (0)