Skip to content

Commit

Permalink
set_fact: 'pgbackrest_install' to configure Postgres backups
Browse files Browse the repository at this point in the history
  • Loading branch information
vitabaks committed Aug 14, 2024
1 parent d8f0f25 commit ec6fea7
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 21 deletions.
38 changes: 35 additions & 3 deletions config_pgcluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
52 changes: 46 additions & 6 deletions deploy_pgcluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
12 changes: 0 additions & 12 deletions roles/cloud-resources/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit ec6fea7

Please sign in to comment.