Skip to content

Commit

Permalink
Install WAL-G from the binary file (#768)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitabaks authored Oct 1, 2024
1 parent 0b47be0 commit 65939d6
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 14 deletions.
72 changes: 58 additions & 14 deletions automation/roles/wal-g/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
- wal_g_auto_conf | default(true) | bool # to be able to disable auto backup settings
tags: wal-g, wal_g, wal_g_conf

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

# Build WAL-G from source code for other Linux distributions
# Install WAL-G from a precompiled binary
# (if 'wal_g_installation_method' is 'binary')
# Note: excluding RHEL 8 as GLIBC version 2.29 or higher is required.
- block:
- name: "Download WAL-G v{{ wal_g_version | replace('v', '') }} binary"
ansible.builtin.get_url:
url: "{{ wal_g_repo }}/{{ wal_g_archive }}"
dest: /tmp/
timeout: 60
validate_certs: false
vars:
wal_g_repo: "https://github.com/wal-g/wal-g/releases/download/v{{ wal_g_version | replace('v', '') }}"
wal_g_archive: "wal-g-pg-ubuntu-20.04-amd64.tar.gz"
environment: "{{ proxy_env | default({}) }}"

# Note: We are using a precompiled binary on Ubuntu 20.04,
# but since Go binaries are cross-platform, it works well on other distributions as well.

- name: Extract WAL-G into /tmp
ansible.builtin.unarchive:
src: "/tmp/wal-g-pg-ubuntu-20.04-amd64.tar.gz"
dest: /tmp/
extra_opts:
- --no-same-owner
remote_src: true

- name: Copy WAL-G binary file to "{{ wal_g_path.split(' ')[0] }}"
ansible.builtin.copy:
src: "/tmp/wal-g-pg-ubuntu-20.04-amd64"
dest: "{{ wal_g_path.split(' ')[0] }}"
mode: u+x,g+x,o+x
remote_src: true
when:
- installation_method == "repo"
- wal_g_installation_method == "binary"
- wal_g_version is version('1.0', '>=')
- (wal_g_installed_version.stderr is search("command not found") or wal_g_installed_version.stdout != wal_g_version)
- not (ansible_os_family == "RedHat" and ansible_distribution_major_version == '8')
tags: wal-g, wal_g, wal_g_install

# Install WAL-G from the source code
# (if 'wal_g_installation_method' is 'src')
- block:
- name: Install lib dependencies to build WAL-G
ansible.builtin.package:
Expand Down Expand Up @@ -103,11 +145,12 @@
when: go_installed_version.stderr is search("command not found") or
go_installed_version.stdout is version(wal_g_latest_version.stdout, '<')

- name: "Download WAL-G v{{ wal_g_version }} source code"
- name: "Download WAL-G v{{ wal_g_version | replace('v', '') }} source code"
ansible.builtin.git:
repo: https://github.com/wal-g/wal-g.git
version: v{{ wal_g_version }}
version: v{{ wal_g_version | replace('v', '') }}
dest: /tmp/wal-g
force: true

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

# older versions of WAL-G (for compatibility)
- block:
- name: "Download WAL-G v{{ wal_g_version }} binary"
- name: "Download WAL-G v{{ wal_g_version | replace('v', '') }} binary"
ansible.builtin.get_url:
url: "https://github.com/wal-g/wal-g/releases/download/v{{ wal_g_version }}/wal-g.linux-amd64.tar.gz"
url: "https://github.com/wal-g/wal-g/releases/download/v{{ wal_g_version | replace('v', '') }}/wal-g.linux-amd64.tar.gz"
dest: /tmp/
timeout: 60
validate_certs: false
Expand All @@ -167,17 +211,17 @@
- --no-same-owner
remote_src: true

- name: Copy WAL-G binary file to "{{ wal_g_path }}"
- name: Copy WAL-G binary file to "{{ wal_g_path.split(' ')[0] }}"
ansible.builtin.copy:
src: "/tmp/wal-g"
dest: "{{ wal_g_path }}"
dest: "{{ wal_g_path.split(' ')[0] }}"
mode: u+x,g+x,o+x
remote_src: true
when:
- installation_method == "repo"
- wal_g_installation_method == "binary"
- wal_g_version is version('0.2.19', '<=')
- (wal_g_installed_version.stderr is search("command not found") or
wal_g_installed_version.stdout != wal_g_version)
- (wal_g_installed_version.stderr is search("command not found") or wal_g_installed_version.stdout != wal_g_version)
tags: wal-g, wal_g, wal_g_install

# installation_method == "file"
Expand All @@ -191,10 +235,10 @@
extra_opts:
- --no-same-owner

- name: Copy WAL-G binary file to "{{ wal_g_path }}"
- name: Copy WAL-G binary file to "{{ wal_g_path.split(' ')[0] }}"
ansible.builtin.copy:
src: "/tmp/{{ wal_g_package_file.split('.tar.gz')[0] | basename }}"
dest: "{{ wal_g_path }}"
dest: "{{ wal_g_path.split(' ')[0] }}"
mode: u+x,g+x,o+x
remote_src: true
when:
Expand All @@ -214,10 +258,10 @@
extra_opts:
- --no-same-owner

- name: Copy WAL-G binary file to "{{ wal_g_path }}"
- name: Copy WAL-G binary file to "{{ wal_g_path.split(' ')[0] }}"
ansible.builtin.copy:
src: "/tmp/wal-g"
dest: "{{ wal_g_path }}"
dest: "{{ wal_g_path.split(' ')[0] }}"
mode: u+x,g+x,o+x
remote_src: true
when:
Expand Down
1 change: 1 addition & 0 deletions automation/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ pg_probackup_patroni_cluster_bootstrap_command: "{{ pg_probackup_command_parts |
# WAL-G
wal_g_install: false # or 'true'
wal_g_version: "3.0.3"
wal_g_installation_method: "binary" # or "src" to build from source code
wal_g_path: "/usr/local/bin/wal-g --config {{ postgresql_home_dir }}/.walg.json"
wal_g_json: # config https://github.com/wal-g/wal-g#configuration
- { option: "AWS_ACCESS_KEY_ID", value: "{{ AWS_ACCESS_KEY_ID | default('') }}" } # define values or pass via --extra-vars
Expand Down

0 comments on commit 65939d6

Please sign in to comment.