From 254c0685fd5daf41ad47953be2dacc41d98af823 Mon Sep 17 00:00:00 2001 From: Ruslan Nigmatullin <60605660+rrrru@users.noreply.github.com> Date: Sun, 23 Jun 2024 22:20:02 +0300 Subject: [PATCH] Add wal_g_path variable; fix "wal-g: not found" (issue 658) (#679) --- .../tests/variables/asserts/wal_g_cron_jobs.yml | 12 ++++++------ roles/wal-g/tasks/main.yml | 16 ++++++++-------- vars/main.yml | 13 +++++++------ 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/molecule/tests/variables/asserts/wal_g_cron_jobs.yml b/molecule/tests/variables/asserts/wal_g_cron_jobs.yml index 92f920f02..aff193f4f 100644 --- a/molecule/tests/variables/asserts/wal_g_cron_jobs.yml +++ b/molecule/tests/variables/asserts/wal_g_cron_jobs.yml @@ -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." @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/roles/wal-g/tasks/main.yml b/roles/wal-g/tasks/main.yml index f43b8d52c..ee3d9dd14 100644 --- a/roles/wal-g/tasks/main.yml +++ b/roles/wal-g/tasks/main.yml @@ -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 @@ -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: @@ -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: @@ -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: @@ -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: diff --git a/vars/main.yml b/vars/main.yml index 6fdb22d39..54c57701f 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -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" } @@ -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 @@ -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 @@ -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"