diff --git a/defaults/main.yaml b/defaults/main.yaml index 6a85a52..25473df 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -1,14 +1,16 @@ wal_g_version: "2.0.1-3.el{{ ansible_distribution_major_version }}" -wal_g_pg: no -wal_g_pg_home_dir: "/var/lib/pgsql" +wal_g_pg: false +wal_g_restore: false +wal_g_config_name: ".walg.json" +wal_g_restore_config_name: ".walg-restore.json" wal_g_pg_binary_name: "wal-g-pg" wal_g_pg_config_owner: "postgres" wal_g_pg_config_group: "postgres" wal_g_pg_backup_owner: "postgres" wal_g_pg_backup_group: "postgres" -wal_g_pg_package_name_regex: 'postgresql.*server' -wal_g_postgresql_major_version: "14" +wal_g_pg_package_name_regex: "postgresql.*server" +wal_g_postgresql_major_version: "15" wal_g_backup_schedule: "" wal_g_backup_retention_schedule: "" @@ -22,7 +24,13 @@ wal_g_default_config: # more options see https://github.com/wal-g/wal-g#configu # WALG_S3_PREFIX: "s3://bucket" # AWS_S3_FORCE_PATH_STYLE: "true" WALG_COMPRESSION_METHOD: "brotli" - PGDATA: "/var/lib/pgsql/{{ wal_g_postgresql_major_version }}/data" + PGDATA: "{{ wal_g_pg_data_dir }}" PGHOST: "/var/run/postgresql" # WALG_LIBSODIUM_KEY: "d82560ddab2b096c56ea8c6573dfdf29de8cd6f2bb5e672d1d3b5a89749b8cbd" WALG_LIBSODIUM_KEY_TRANSFORM: "hex" + +wal_g_default_restore_config: + WALG_COMPRESSION_METHOD: "brotli" + PGDATA: "{{ wal_g_pg_data_dir }}" + PGHOST: "/var/run/postgresql" + WALG_LIBSODIUM_KEY_TRANSFORM: "hex" diff --git a/tasks/main.yml b/tasks/main.yml index fd7aa0e..5ac6f28 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,4 +1,21 @@ --- +- name: Load a variable file based on the OS type + include_vars: "{{ lookup('first_found', params) }}" + vars: + params: + files: + - "{{ ansible_facts['distribution'] }}.yaml" + - "{{ ansible_facts['os_family'] }}.yaml" + paths: + - "vars" + tags: wal_g_vars + + +- name: Set facts about needed vars + set_fact: + wal_g_pg_home_dir: "{{ wal_g_pg_home_dir }}" + wal_g_pg_data_dir: "{{ wal_g_pg_data_dir }}" + - name: "Include install WAL-G {{ wal_g_version }} for PostgreSQL" include_tasks: pg.yaml when: wal_g_pg diff --git a/tasks/pg.yaml b/tasks/pg.yaml index 5c5e1c5..4c31869 100644 --- a/tasks/pg.yaml +++ b/tasks/pg.yaml @@ -4,7 +4,7 @@ name: "epel-release" state: present -- name: "Install WAL-G for PostgreSQL" +- name: "Install WAL-G {{ wal_g_version }} for PostgreSQL" dnf: name: "wal-g{{ ('-' ~ wal_g_version) | default('') }}" state: installed @@ -31,9 +31,23 @@ - name: "Generate conf file walg.json" copy: content: "{{ wal_g_combined_config | to_nice_json }}" - dest: "{{ wal_g_pg_home_dir }}/.walg.json" + dest: "{{ wal_g_pg_home_dir }}/{{ wal_g_config_name }}" owner: "{{ wal_g_pg_config_owner }}" group: "{{ wal_g_pg_config_group }}" mode: 0644 tags: wal-g, wal_g, wal_g_conf +- name: Create wal-g restore config + when: wal_g_restore + block: + - name: Merge user options for WAL-G part of restore config + set_fact: + wal_g_restore_combined_config: "{{ wal_g_default_restore_config | combine(wal_g_restore_config|default({}), recursive=true) }}" + + - name: "Generate conf file walg-restore.json" + copy: + content: "{{ wal_g_restore_combined_config | to_nice_json }}" + dest: "{{ wal_g_pg_home_dir }}/{{ wal_g_restore_config_name }}" + owner: "{{ wal_g_pg_config_owner }}" + group: "{{ wal_g_pg_config_group }}" + mode: 0644 diff --git a/templates/backup-permanent.sh.j2 b/templates/backup-permanent.sh.j2 index 4f33e32..377d875 100644 --- a/templates/backup-permanent.sh.j2 +++ b/templates/backup-permanent.sh.j2 @@ -4,7 +4,7 @@ flock -x 200 role=$(curl -k -s http://127.0.0.1:8008 || curl -k -s https://127.0.0.1:8008 | jq '.role') if [ "${role}" == "\"master\"" ] ; then - {{ wal_g_pg_binary_name }} backup-push {{ wal_g_pg_home_dir }}/{{ wal_g_postgresql_major_version }}/data --full --permanent 2>&1 | tee -a /var/log/postgresql/backup-permanent.log + {{ wal_g_pg_binary_name }} --config {{ wal_g_pg_home_dir }}/{{ wal_g_config_name }} backup-push {{ wal_g_pg_data_dir }} --full --permanent 2>&1 | tee -a /var/log/postgresql/backup-permanent.log else echo "" fi diff --git a/templates/backup-retention.sh.j2 b/templates/backup-retention.sh.j2 index b29879c..31d125d 100644 --- a/templates/backup-retention.sh.j2 +++ b/templates/backup-retention.sh.j2 @@ -4,7 +4,7 @@ flock -x 200 role=$(curl -k -s http://127.0.0.1:8008 || curl -k -s https://127.0.0.1:8008 | jq '.role') if [ "${role}" == "\"master\"" ] ; then - {{ wal_g_pg_binary_name }} retain {{ wal_g_backup_retention_number }} --confirm --use-sentinel-time 2>&1 | tee -a /var/log/postgresql/backup-retention.log + {{ wal_g_pg_binary_name }} --config {{ wal_g_pg_home_dir }}/{{ wal_g_config_name }} retain {{ wal_g_backup_retention_number }} --confirm --use-sentinel-time 2>&1 | tee -a /var/log/postgresql/backup-retention.log else echo "" fi diff --git a/templates/backup.sh.j2 b/templates/backup.sh.j2 index 953ba4c..dc4cc02 100644 --- a/templates/backup.sh.j2 +++ b/templates/backup.sh.j2 @@ -4,7 +4,7 @@ flock -x 200 role=$(curl -k -s http://127.0.0.1:8008 || curl -k -s https://127.0.0.1:8008 | jq '.role') if [ "${role}" == "\"master\"" ] ; then - {{ wal_g_pg_binary_name }} backup-push {{ wal_g_pg_home_dir }}/{{ wal_g_postgresql_major_version }}/data --full 2>&1 | tee -a /var/log/postgresql/backup.log + {{ wal_g_pg_binary_name }} --config {{ wal_g_pg_home_dir }}/{{ wal_g_config_name }} backup-push {{ wal_g_pg_data_dir }} --full 2>&1 | tee -a /var/log/postgresql/backup.log else echo "" fi diff --git a/vars/Debian.yaml b/vars/Debian.yaml new file mode 100644 index 0000000..cc638e7 --- /dev/null +++ b/vars/Debian.yaml @@ -0,0 +1,3 @@ +wal_g_pg_home_dir: "/var/lib/postgresql" +wal_g_pg_data_dir: "{{ wal_g_pg_home_dir }}/{{ wal_g_pg_major_version }}/{{ wal_g_pg_cluster_name }}" +wal_g_pg_cluster_name: "main" diff --git a/vars/RedHat.yaml b/vars/RedHat.yaml new file mode 100644 index 0000000..0d7fcca --- /dev/null +++ b/vars/RedHat.yaml @@ -0,0 +1,3 @@ +wal_g_pg_home_dir: "/var/lib/pgsql" +wal_g_pg_data_dir: "{{ wal_g_pg_home_dir }}/{{ postgresql_major_version }}/data" + diff --git a/vars/main.yaml b/vars/main.yaml new file mode 100644 index 0000000..e69de29