From ec6fea730d5830f32658ccff348376df2d0b7446 Mon Sep 17 00:00:00 2001 From: Vitaliy Kukharik Date: Wed, 14 Aug 2024 13:21:21 +0300 Subject: [PATCH] set_fact: 'pgbackrest_install' to configure Postgres backups --- config_pgcluster.yml | 38 ++++++++++++++++++-- deploy_pgcluster.yml | 52 ++++++++++++++++++++++++---- roles/cloud-resources/tasks/main.yml | 12 ------- 3 files changed, 81 insertions(+), 21 deletions(-) diff --git a/config_pgcluster.yml b/config_pgcluster.yml index 7f12f34a2..fe1e4e562 100644 --- a/config_pgcluster.yml +++ b/config_pgcluster.yml @@ -7,6 +7,18 @@ - name: Include main variables ansible.builtin.include_vars: "vars/main.yml" tags: always + # set_fact: 'pgbackrest_install' to configure Postgres backups (TODO: Add the ability to configure backups in the UI) + # Note: Applicable only for "aws", "gcp", "azure", because: + # "digitalocean" - requires the Spaces access keys "AWS_ACCESS_KEY_ID" and "AWS_SECRET_ACCESS_KEY" + # "hetzner" - currently, Hetzner Cloud does not provide S3 storage + - name: "Set variable: 'pgbackrest_install' to configure Postgres backups" + ansible.builtin.set_fact: + pgbackrest_install: true + when: + - not (pgbackrest_install | bool or wal_g_install | bool) + - cloud_provider | default('') | lower in ['aws', 'gcp', 'azure'] + - pgbackrest_auto_conf | default(true) | bool # to be able to disable auto backup settings + tags: always roles: - role: cloud-resources when: cloud_provider | default('') | length > 0 @@ -80,6 +92,17 @@ - "Cluster Leader: {{ ansible_hostname }}" when: inventory_hostname in groups['primary'] + # if 'cloud_provider' is 'aws', 'gcp', or 'azure' + # set_fact: 'pgbackrest_install' to configure Postgres backups (TODO: Add the ability to configure backups in the UI) + - name: "Set variable: 'pgbackrest_install' to configure Postgres backups" + ansible.builtin.set_fact: + pgbackrest_install: true + when: + - not (pgbackrest_install | bool or wal_g_install | bool) + - cloud_provider | default('') | lower in ['aws', 'gcp', 'azure'] + - pgbackrest_auto_conf | default(true) | bool # to be able to disable auto backup settings + tags: always + roles: - role: pre-checks vars: @@ -196,11 +219,20 @@ - name: Include OS-specific variables ansible.builtin.include_vars: "vars/{{ ansible_os_family }}.yml" tags: always + + # if 'cloud_provider' is 'aws', 'gcp', or 'azure' + # set_fact: 'pgbackrest_install' to configure Postgres backups (TODO: Add the ability to configure backups in the UI) + - name: "Set variable: 'pgbackrest_install' to configure Postgres backups" + ansible.builtin.set_fact: + pgbackrest_install: true + when: + - not (pgbackrest_install | bool or wal_g_install | bool) + - cloud_provider | default('') | lower in ['aws', 'gcp', 'azure'] + - pgbackrest_auto_conf | default(true) | bool # to be able to disable auto backup settings + tags: always roles: - role: pgbackrest - when: pgbackrest_install | bool or - (pgbackrest_auto_conf | default(true) | bool and cloud_provider | default('') | lower in ['aws', 'gcp', 'azure']) - # TODO: Add the ability to configure backups in the UI + when: pgbackrest_install | bool - name: config_pgcluster.yml | Restart patroni on secondary after config settings if need hosts: secondary diff --git a/deploy_pgcluster.yml b/deploy_pgcluster.yml index 8363962be..c7efcb40c 100644 --- a/deploy_pgcluster.yml +++ b/deploy_pgcluster.yml @@ -7,6 +7,18 @@ - name: Include main variables ansible.builtin.include_vars: "vars/main.yml" tags: always + # set_fact: 'pgbackrest_install' to configure Postgres backups (TODO: Add the ability to configure backups in the UI) + # Note: Applicable only for "aws", "gcp", "azure", because: + # "digitalocean" - requires the Spaces access keys "AWS_ACCESS_KEY_ID" and "AWS_SECRET_ACCESS_KEY" + # "hetzner" - currently, Hetzner Cloud does not provide S3 storage + - name: "Set variable: 'pgbackrest_install' to configure Postgres backups" + ansible.builtin.set_fact: + pgbackrest_install: true + when: + - not (pgbackrest_install | bool or wal_g_install | bool) + - cloud_provider | default('') | lower in ['aws', 'gcp', 'azure'] + - pgbackrest_auto_conf | default(true) | bool # to be able to disable auto backup settings + tags: always roles: - role: cloud-resources when: cloud_provider | default('') | length > 0 @@ -60,6 +72,17 @@ product_name: "{{ ansible_product_name | default('N/A') }}" tags: always + # if 'cloud_provider' is 'aws', 'gcp', or 'azure' + # set_fact: 'pgbackrest_install' to configure Postgres backups (TODO: Add the ability to configure backups in the UI) + - name: "Set variable: 'pgbackrest_install' to configure Postgres backups" + ansible.builtin.set_fact: + pgbackrest_install: true + when: + - not (pgbackrest_install | bool or wal_g_install | bool) + - cloud_provider | default('') | lower in ['aws', 'gcp', 'azure'] + - pgbackrest_auto_conf | default(true) | bool # to be able to disable auto backup settings + tags: always + roles: # (optional) if 'ssh_public_keys' is defined - role: authorized-keys @@ -277,11 +300,19 @@ ansible.builtin.include_vars: "vars/{{ ansible_os_family }}.yml" tags: always + # if 'cloud_provider' is 'aws', 'gcp', or 'azure' + # set_fact: 'pgbackrest_install' to configure Postgres backups (TODO: Add the ability to configure backups in the UI) + - name: "Set variable: 'pgbackrest_install' to configure Postgres backups" + ansible.builtin.set_fact: + pgbackrest_install: true + when: + - not (pgbackrest_install | bool or wal_g_install | bool) + - cloud_provider | default('') | lower in ['aws', 'gcp', 'azure'] + - pgbackrest_auto_conf | default(true) | bool # to be able to disable auto backup settings + tags: always roles: - role: pgbackrest - when: pgbackrest_install | bool or - (pgbackrest_auto_conf | default(true) | bool and cloud_provider | default('') | lower in ['aws', 'gcp', 'azure']) - # TODO: Add the ability to configure backups in the UI + when: pgbackrest_install | bool - name: deploy_pgcluster.yml | PostgreSQL Cluster Deployment hosts: postgres_cluster @@ -305,6 +336,17 @@ ansible.builtin.include_vars: "vars/{{ ansible_os_family }}.yml" tags: always + # if 'cloud_provider' is 'aws', 'gcp', or 'azure' + # set_fact: 'pgbackrest_install' to configure Postgres backups (TODO: Add the ability to configure backups in the UI) + - name: "Set variable: 'pgbackrest_install' to configure Postgres backups" + ansible.builtin.set_fact: + pgbackrest_install: true + when: + - not (pgbackrest_install | bool or wal_g_install | bool) + - cloud_provider | default('') | lower in ['aws', 'gcp', 'azure'] + - pgbackrest_auto_conf | default(true) | bool # to be able to disable auto backup settings + tags: always + roles: - role: wal-g when: wal_g_install|bool @@ -322,9 +364,7 @@ - role: patroni - role: pgbackrest/stanza-create - when: pgbackrest_install | bool or - (pgbackrest_auto_conf | default(true) | bool and cloud_provider | default('') | lower in ['aws', 'gcp', 'azure']) - # TODO: Add the ability to configure backups in the UI + when: pgbackrest_install | bool - role: vip-manager when: not with_haproxy_load_balancing|bool and diff --git a/roles/cloud-resources/tasks/main.yml b/roles/cloud-resources/tasks/main.yml index bb9078b5b..0c62f66d6 100644 --- a/roles/cloud-resources/tasks/main.yml +++ b/roles/cloud-resources/tasks/main.yml @@ -41,18 +41,6 @@ - tmp_ssh_key_result.ssh_public_key is defined - tmp_ssh_key_result.ssh_public_key | length > 0 -# set_fact: 'pgbackrest_install' to configure Postgres backups (TODO: Add the ability to configure backups in the UI) -# Note: Applicable only for "aws", "gcp", "azure", because: - # "digitalocean" - requires the Spaces access keys "AWS_ACCESS_KEY_ID" and "AWS_SECRET_ACCESS_KEY" - # "hetzner" - currently, Hetzner Cloud does not provide S3 storage -- name: "Set variable: 'pgbackrest_install' to configure Postgres backups" - ansible.builtin.set_fact: - pgbackrest_install: true - when: - - not (pgbackrest_install | bool or wal_g_install | bool) - - cloud_provider | default('') | lower in ['aws', 'gcp', 'azure'] - - pgbackrest_auto_conf | default(true) | bool # to be able to disable auto backup settings - - name: Import tasks for AWS ansible.builtin.import_tasks: aws.yml when: cloud_provider | lower == 'aws'