Skip to content

Commit

Permalink
Add wal_g_path variable; fix "wal-g: not found" (issue 658) (#679)
Browse files Browse the repository at this point in the history
  • Loading branch information
rrrru authored Jun 23, 2024
1 parent 9ac0428 commit 254c068
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
12 changes: 6 additions & 6 deletions molecule/tests/variables/asserts/wal_g_cron_jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
ansible.builtin.assert:
that:
- wal_g_backup_command[0] == "curl -I -s http://{{ inventory_hostname }}:{{ patroni_restapi_port }} | grep 200"
- wal_g_backup_command[1] == " && wal-g backup-push {{ postgresql_data_dir }} > {{ postgresql_log_dir }}/walg_backup.log 2>&1"
- wal_g_backup_command[1] == " && {{ wal_g_path }} backup-push {{ postgresql_data_dir }} > {{ postgresql_log_dir }}/walg_backup.log 2>&1"
- wal_g_delete_command[0] == "curl -I -s http://{{ inventory_hostname }}:{{ patroni_restapi_port }} | grep 200"
- wal_g_delete_command[1] == " && wal-g delete retain FULL 4 --confirm > {{ postgresql_log_dir }}/walg_delete.log 2>&1"
- wal_g_delete_command[1] == " && {{ wal_g_path }} delete retain FULL 4 --confirm > {{ postgresql_log_dir }}/walg_delete.log 2>&1"
fail_msg: "Test failed: wal_g_backup_command or wal_g_delete_command do not have the expected content."
success_msg: "Test passed: wal_g_backup_command and wal_g_delete_command have the expected content."

Expand All @@ -45,7 +45,7 @@
- name: Molecule.tests.variables.asserts.wal_g_cron_jobs | Debian | Define Expected First wal_g_cron Job
run_once: true
ansible.builtin.set_fact: # yamllint disable rule:line-length
origin_wal_g_cron_jobs_create_job: "curl -I -s http://{{ inventory_hostname }}:{{ patroni_restapi_port }} | grep 200 && wal-g backup-push {{ postgresql_data_dir }} > {{ postgresql_log_dir }}/walg_backup.log 2>&1"
origin_wal_g_cron_jobs_create_job: "curl -I -s http://{{ inventory_hostname }}:{{ patroni_restapi_port }} | grep 200 && {{ wal_g_path }} backup-push {{ postgresql_data_dir }} > {{ postgresql_log_dir }}/walg_backup.log 2>&1"

# 🖨️ Display the first wal_g_cron job for Debian for debugging purposes
- name: Molecule.tests.variables.asserts.wal_g_cron_jobs | Debian | Debug First wal_g_cron Job
Expand All @@ -66,7 +66,7 @@
- name: Molecule.tests.variables.asserts.wal_g_cron_jobs | Debian | Define Expected Second wal_g_cron Job
run_once: true
ansible.builtin.set_fact: # yamllint disable rule:line-length
origin_wal_g_cron_jobs_delete_job: "curl -I -s http://{{ inventory_hostname }}:{{ patroni_restapi_port }} | grep 200 && wal-g delete retain FULL 4 --confirm > {{ postgresql_log_dir }}/walg_delete.log 2>&1"
origin_wal_g_cron_jobs_delete_job: "curl -I -s http://{{ inventory_hostname }}:{{ patroni_restapi_port }} | grep 200 && {{ wal_g_path }} delete retain FULL 4 --confirm > {{ postgresql_log_dir }}/walg_delete.log 2>&1"

# 🖨️ Display the second wal_g_cron job for Debian for debugging purposes
- name: Molecule.tests.variables.asserts.wal_g_cron_jobs | Debian | Debug Second wal_g_cron Job
Expand Down Expand Up @@ -97,7 +97,7 @@
- name: Molecule.tests.variables.asserts.wal_g_cron_jobs | RedHat | Define Expected First wal_g_cron Job
run_once: true
ansible.builtin.set_fact: # yamllint disable rule:line-length
origin_wal_g_cron_jobs_create_job: "curl -I -s http://{{ inventory_hostname }}:{{ patroni_restapi_port }} | grep 200 && wal-g backup-push {{ postgresql_data_dir }} > {{ postgresql_log_dir }}/walg_backup.log 2>&1"
origin_wal_g_cron_jobs_create_job: "curl -I -s http://{{ inventory_hostname }}:{{ patroni_restapi_port }} | grep 200 && {{ wal_g_path }} backup-push {{ postgresql_data_dir }} > {{ postgresql_log_dir }}/walg_backup.log 2>&1"

# 🖨️ Display the first wal_g_cron job for RedHat for debugging purposes
- name: Molecule.tests.variables.asserts.wal_g_cron_jobs | RedHat | Debug First wal_g_cron Job
Expand All @@ -118,7 +118,7 @@
- name: Molecule.tests.variables.asserts.wal_g_cron_jobs | RedHat | Define Expected Second wal_g_cron Job
run_once: true
ansible.builtin.set_fact: # yamllint disable rule:line-length
origin_wal_g_cron_jobs_delete_job: "curl -I -s http://{{ inventory_hostname }}:{{ patroni_restapi_port }} | grep 200 && wal-g delete retain FULL 4 --confirm > {{ postgresql_log_dir }}/walg_delete.log 2>&1"
origin_wal_g_cron_jobs_delete_job: "curl -I -s http://{{ inventory_hostname }}:{{ patroni_restapi_port }} | grep 200 && {{ wal_g_path }} delete retain FULL 4 --confirm > {{ postgresql_log_dir }}/walg_delete.log 2>&1"

# 🖨️ Display the second wal_g_cron job for RedHat for debugging purposes
- name: Molecule.tests.variables.asserts.wal_g_cron_jobs | RedHat | Debug Second wal_g_cron Job
Expand Down
16 changes: 8 additions & 8 deletions roles/wal-g/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
- name: Check if WAL-G is already installed
ansible.builtin.shell: |
set -o pipefail;
wal-g --version | awk {'print $3'} | tr -d 'v'
"{{ wal_g_path }}" --version | awk {'print $3'} | tr -d 'v'
args:
executable: /bin/bash
changed_when: false
Expand Down Expand Up @@ -42,7 +42,7 @@
- name: Copy WAL-G binary file to /usr/local/bin/
ansible.builtin.copy:
src: "/tmp/wal-g-pg-ubuntu-{{ ansible_distribution_version }}-amd64"
dest: /usr/local/bin/wal-g
dest: "{{ wal_g_path }}"
mode: u+x,g+x,o+x
remote_src: true
when:
Expand Down Expand Up @@ -184,10 +184,10 @@
- --no-same-owner
remote_src: true

- name: Copy WAL-G binary file to /usr/local/bin/
- name: Copy WAL-G binary file to "{{ wal_g_path }}"
ansible.builtin.copy:
src: "/tmp/wal-g"
dest: /usr/local/bin/
dest: "{{ wal_g_path }}"
mode: u+x,g+x,o+x
remote_src: true
when:
Expand All @@ -208,10 +208,10 @@
extra_opts:
- --no-same-owner

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

- name: Copy WAL-G binary file to /usr/local/bin/
- name: Copy WAL-G binary file to "{{ wal_g_path }}"
ansible.builtin.copy:
src: "/tmp/wal-g"
dest: /usr/local/bin/
dest: "{{ wal_g_path }}"
mode: u+x,g+x,o+x
remote_src: true
when:
Expand Down
13 changes: 7 additions & 6 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ pgbackrest:
- { option: "keep_data", value: "True" }
- { option: "no_params", value: "True" }
wal_g:
- { option: "command", value: "wal-g backup-fetch {{ postgresql_data_dir }} LATEST" }
- { option: "command", value: "{{ wal_g_path }} backup-fetch {{ postgresql_data_dir }} LATEST" }
- { option: "no_params", value: "True" }
basebackup:
- { option: "max-rate", value: "100M" }
Expand All @@ -434,7 +434,7 @@ pg_probackup:

# "restore_command" written to recovery.conf when configuring follower (create replica)
postgresql_restore_command: ""
# postgresql_restore_command: "wal-g wal-fetch %f %p" # restore WAL-s using WAL-G
# postgresql_restore_command: "{{ wal_g_path }} wal-fetch %f %p" # restore WAL-s using WAL-G
# postgresql_restore_command: "pgbackrest --stanza={{ pgbackrest_stanza }} archive-get %f %p" # restore WAL-s using pgbackrest

# postgresql_restore_command: "pg_probackup-{{ pg_probackup_version }} archive-get -B
Expand Down Expand Up @@ -462,6 +462,7 @@ pg_probackup_patroni_cluster_bootstrap_command: "{{ pg_probackup_command_parts |
# WAL-G
wal_g_install: false # or 'true'
wal_g_version: "3.0.0"
wal_g_path: "/usr/local/bin/wal-g"
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
- { option: "AWS_SECRET_ACCESS_KEY", value: "{{ AWS_SECRET_ACCESS_KEY | default('') }}" } # define values or pass via --extra-vars
Expand All @@ -475,17 +476,17 @@ wal_g_json: # config https://github.com/wal-g/wal-g#configuration
# - { option: "AWS_S3_FORCE_PATH_STYLE", value: "true" } # to use Minio.io S3-compatible storage
# - { option: "AWS_ENDPOINT", value: "http://minio:9000" } # to use Minio.io S3-compatible storage
# - { option: "", value: "" }
wal_g_archive_command: "wal-g wal-push %p"
wal_g_patroni_cluster_bootstrap_command: "wal-g backup-fetch {{ postgresql_data_dir }} LATEST"
wal_g_archive_command: "{{ wal_g_path }} wal-push %p"
wal_g_patroni_cluster_bootstrap_command: "{{ wal_g_path }} backup-fetch {{ postgresql_data_dir }} LATEST"

# Define job_parts outside of wal_g_cron_jobs
# ⚠️ Ensure there is a space at the beginning of each part to prevent commands from concatenating.
wal_g_backup_command:
- "curl -I -s http://{{ inventory_hostname }}:{{ patroni_restapi_port }} | grep 200"
- " && wal-g backup-push {{ postgresql_data_dir }} > {{ postgresql_log_dir }}/walg_backup.log 2>&1"
- " && {{ wal_g_path }} backup-push {{ postgresql_data_dir }} > {{ postgresql_log_dir }}/walg_backup.log 2>&1"
wal_g_delete_command:
- "curl -I -s http://{{ inventory_hostname }}:{{ patroni_restapi_port }} | grep 200"
- " && wal-g delete retain FULL 4 --confirm > {{ postgresql_log_dir }}/walg_delete.log 2>&1"
- " && {{ wal_g_path }} delete retain FULL 4 --confirm > {{ postgresql_log_dir }}/walg_delete.log 2>&1"

wal_g_cron_jobs:
- name: "WAL-G: Create daily backup"
Expand Down

0 comments on commit 254c068

Please sign in to comment.