diff --git a/config_pgcluster.yml b/config_pgcluster.yml index b6a131352..6d0b3a277 100644 --- a/config_pgcluster.yml +++ b/config_pgcluster.yml @@ -9,7 +9,7 @@ tags: always roles: - role: cloud-resources - when: provision | lower != 'none' + when: cloud_provider | default('') | length > 0 tags: always - name: config_pgcluster.yml | Check the PostgreSQL cluster state and perform pre-checks diff --git a/deploy_pgcluster.yml b/deploy_pgcluster.yml index a90361b9a..1270a5402 100644 --- a/deploy_pgcluster.yml +++ b/deploy_pgcluster.yml @@ -9,7 +9,7 @@ tags: always roles: - role: cloud-resources - when: provision | lower != 'none' + when: cloud_provider | default('') | length > 0 tags: always - name: deploy_pgcluster.yml | Perform pre-checks diff --git a/roles/cloud-resources/defaults/main.yml b/roles/cloud-resources/defaults/main.yml index 8a3a5f4c6..104003f71 100644 --- a/roles/cloud-resources/defaults/main.yml +++ b/roles/cloud-resources/defaults/main.yml @@ -1,7 +1,7 @@ # yamllint disable rule:line-length --- -provision: none # Platform for server creation. Available options: 'aws', 'gcp', 'azure', 'digitalocean', 'hetzner'. Default: none (do not create). +cloud_provider: "{{ provision | default('') }}" # Specifies the Cloud provider for server creation. Available options: 'aws', 'gcp', 'azure', 'digitalocean', 'hetzner'. state: present # Set to 'present' to create a server, 'absent' to delete. servers_count: 3 # Number of servers in the cluster. Servers will be automatically named with suffixes 01, 02, 03, etc. @@ -31,26 +31,26 @@ database_public_access: false # Allow access to the database from the public ne database_public_allowed_ips: "" # (comma-separated list of IP addresses in CIDR format) If empty, then public access is allowed for any IP address. # Backups (if 'pgbackrest_install' or 'wal_g_install' is 'true') -aws_s3_bucket_create: true # if 'provision=aws' +aws_s3_bucket_create: true # if 'cloud_provider=aws' aws_s3_bucket_name: "backups-{{ patroni_cluster_name }}" # Name of the S3 bucket. Bucket naming rules: https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html aws_s3_bucket_region: "{{ server_location }}" # The AWS region to use. aws_s3_bucket_object_lock_enabled: false # Whether S3 Object Lock to be enabled. aws_s3_bucket_encryption: "AES256" # Describes the default server-side encryption to apply to new objects in the bucket. Choices: "AES256", "aws:kms" aws_s3_bucket_absent: false # Allow to delete S3 bucket when deleting a cluster servers using the 'state=absent' variable. -gcp_bucket_create: true # if 'provision=gcp' +gcp_bucket_create: true # if 'cloud_provider=gcp' gcp_bucket_name: "backups-{{ patroni_cluster_name }}" # Name of the GCS bucket. gcp_bucket_storage_class: "MULTI_REGIONAL" # The bucket’s default storage class. Values include: MULTI_REGIONAL, REGIONAL, STANDARD, NEARLINE, COLDLINE, ARCHIVE, DURABLE_REDUCED_AVAILABILITY. gcp_bucket_default_object_acl: "projectPrivate" # Apply a predefined set of default object access controls to this bucket. gcp_bucket_absent: false # Allow to delete GCS bucket when deleting a cluster servers using the 'state=absent' variable. -azure_blob_storage_create: true # if 'provision=azure' +azure_blob_storage_create: true # if 'cloud_provider=azure' azure_blob_storage_name: "backups-{{ patroni_cluster_name }}" # Name of a blob container within the storage account. azure_blob_storage_account_name: "{{ patroni_cluster_name | lower | replace('-', '') | truncate(24, true, '') }}" # Storage account name must be between 3 and 24 characters in length and use numbers and lower-case letters only. azure_blob_storage_account_type: "Standard_RAGRS" # Type of storage account. Values include: Standard_LRS, Standard_GRS, Standard_RAGRS, Standard_ZRS, Standard_RAGZRS, Standard_GZRS, Premium_LRS, Premium_ZRS. azure_blob_storage_absent: false # Allow to delete Azure Blob Storage when deleting a cluster servers using the 'state=absent' variable. -digital_ocean_spaces_create: true # if 'provision=digitalocean' +digital_ocean_spaces_create: true # if 'cloud_provider=digitalocean' digital_ocean_spaces_name: "backups-{{ patroni_cluster_name | lower }}" # Name of the Spaces Object Storage (S3 bucket). digital_ocean_spaces_region: "nyc3" # The region to create the Space in. digital_ocean_spaces_absent: false # Allow to delete Spaces Object Storage when deleting a cluster servers using the 'state=absent' variable. diff --git a/roles/cloud-resources/tasks/main.yml b/roles/cloud-resources/tasks/main.yml index 52074893a..44ab0a6c0 100644 --- a/roles/cloud-resources/tasks/main.yml +++ b/roles/cloud-resources/tasks/main.yml @@ -7,7 +7,7 @@ - "Please specify value for variables: 'server_type', 'server_image', 'server_location', 'volume_size'." when: state == 'present' and (server_type | length < 1 or - (server_image | length < 1 and provision != 'azure') or + (server_image | length < 1 and cloud_provider != 'azure') or server_location | length < 1 or volume_size | length < 1) @@ -43,22 +43,22 @@ - name: Import tasks for AWS ansible.builtin.import_tasks: aws.yml - when: provision | lower == 'aws' + when: cloud_provider | lower == 'aws' - name: Import tasks for GCP ansible.builtin.import_tasks: gcp.yml - when: provision | lower == 'gcp' + when: cloud_provider | lower == 'gcp' - name: Import tasks for Azure ansible.builtin.import_tasks: azure.yml - when: provision | lower == 'azure' + when: cloud_provider | lower == 'azure' - name: Import tasks for DigitalOcean ansible.builtin.import_tasks: digitalocean.yml - when: provision | lower in ['digitalocean', 'do'] + when: cloud_provider | lower in ['digitalocean', 'do'] - name: Import tasks for Hetzner Cloud ansible.builtin.import_tasks: hetzner.yml - when: provision | lower == 'hetzner' + when: cloud_provider | lower == 'hetzner' ... diff --git a/roles/mount/tasks/main.yml b/roles/mount/tasks/main.yml index 17c1c6176..fdc63479a 100644 --- a/roles/mount/tasks/main.yml +++ b/roles/mount/tasks/main.yml @@ -1,7 +1,7 @@ --- - block: - # Try to detect an empty disk (if provision != 'none') + # Try to detect an empty disk (if 'cloud_provider' is defined) - name: Detect empty volume ansible.builtin.shell: | set -o pipefail; @@ -11,7 +11,7 @@ executable: /bin/bash register: lsblk_disk changed_when: false - when: (provision is defined and provision | lower != 'none') and mount[0].src | length < 1 + when: (cloud_provider | default('') | length > 0) and mount[0].src | length < 1 # Show the error message, if empty volume is not detected - name: Empty volume is not detected diff --git a/roles/pgbackrest/tasks/auto_conf.yml b/roles/pgbackrest/tasks/auto_conf.yml index dda5b0a19..8def151a4 100644 --- a/roles/pgbackrest/tasks/auto_conf.yml +++ b/roles/pgbackrest/tasks/auto_conf.yml @@ -1,7 +1,7 @@ # yamllint disable rule:line-length --- -# AWS S3 bucket (if 'provision=aws') +# AWS S3 bucket (if 'cloud_provider=aws') - name: "Set variable 'pgbackrest_conf' for backup in AWS S3 bucket" ansible.builtin.set_fact: pgbackrest_conf: @@ -33,9 +33,9 @@ - { option: "recovery-option", value: "recovery_target_action=promote" } - { option: "pg1-path", value: "{{ pg_data_mount_path | default('/pgdata') }}/{{ postgresql_version }}/{{ patroni_cluster_name }}" } no_log: true # do not output contents to the ansible log - when: provision | default('') | lower == 'aws' + when: cloud_provider | default('') | lower == 'aws' -# GCS Bucket (if 'provision=gcp') +# GCS Bucket (if 'cloud_provider=gcp') - block: - name: "Set variable 'pgbackrest_conf' for backup in GCS Bucket" ansible.builtin.set_fact: @@ -95,9 +95,9 @@ group: "postgres" no_log: true # do not output GCP service account contents to the ansible log when: gcs_key_file is defined and gcs_key_file | length > 0 - when: provision | default('') | lower == 'gcp' + when: cloud_provider | default('') | lower == 'gcp' -# Azure Blob Storage (if 'provision=azure') +# Azure Blob Storage (if 'cloud_provider=azure') - name: "Set variable 'pgbackrest_conf' for backup in Azure Blob Storage" ansible.builtin.set_fact: pgbackrest_conf: @@ -128,9 +128,9 @@ - { option: "recovery-option", value: "recovery_target_action=promote" } - { option: "pg1-path", value: "{{ pg_data_mount_path | default('/pgdata') }}/{{ postgresql_version }}/{{ patroni_cluster_name }}" } no_log: true # do not output contents to the ansible log - when: provision | default('') | lower == 'azure' + when: cloud_provider | default('') | lower == 'azure' -# DigitalOcean Spaces Object Storage (if 'provision=digitalocean') +# DigitalOcean Spaces Object Storage (if 'cloud_provider=digitalocean') - name: "Set variable 'pgbackrest_conf' for backup in DigitalOcean Spaces Object Storage" ansible.builtin.set_fact: pgbackrest_conf: @@ -163,6 +163,6 @@ - { option: "recovery-option", value: "recovery_target_action=promote" } - { option: "pg1-path", value: "{{ pg_data_mount_path | default('/pgdata') }}/{{ postgresql_version }}/{{ patroni_cluster_name }}" } no_log: true # do not output contents to the ansible log - when: provision | default('') | lower == 'digitalocean' + when: cloud_provider | default('') | lower == 'digitalocean' ... diff --git a/roles/pgbackrest/tasks/main.yml b/roles/pgbackrest/tasks/main.yml index ecb0aaeac..05fc23a5b 100644 --- a/roles/pgbackrest/tasks/main.yml +++ b/roles/pgbackrest/tasks/main.yml @@ -1,9 +1,9 @@ --- # Automatic setup of the backup configuration based on the selected cloud provider. -# if 'provision' is 'aws', 'gcp', 'azure', 'digitalocean'. +# if 'cloud_provider' is 'aws', 'gcp', 'azure', 'digitalocean'. - ansible.builtin.import_tasks: auto_conf.yml - when: provision | default('none') != 'none' + when: cloud_provider | default('') | length > 0 tags: pgbackrest, pgbackrest_conf - block: # Debian pgdg repo diff --git a/roles/wal-g/tasks/auto_conf.yml b/roles/wal-g/tasks/auto_conf.yml index 5f9b3189c..35450e621 100644 --- a/roles/wal-g/tasks/auto_conf.yml +++ b/roles/wal-g/tasks/auto_conf.yml @@ -1,7 +1,7 @@ # yamllint disable rule:line-length --- -# AWS S3 bucket (if 'provision=aws') +# AWS S3 bucket (if 'cloud_provider=aws') - name: "Set variable 'wal_g_json' for backup in AWS S3 bucket" ansible.builtin.set_fact: wal_g_json: @@ -19,9 +19,9 @@ - { option: "PGPORT", value: "{{ postgresql_port | default('5432') }}" } - { option: "PGUSER", value: "{{ patroni_superuser_username | default('postgres') }}" } no_log: true # do not output contents to the ansible log - when: provision | default('') | lower == 'aws' + when: cloud_provider | default('') | lower == 'aws' -# GCS Bucket (if 'provision=gcp') +# GCS Bucket (if 'cloud_provider=gcp') - block: - name: "Set variable 'wal_g_json' for backup in GCS Bucket" ansible.builtin.set_fact: @@ -68,9 +68,9 @@ group: "postgres" no_log: true # do not output GCP service account contents to the ansible log when: gcs_key_file is defined and gcs_key_file | length > 0 - when: provision | default('') | lower == 'gcp' + when: cloud_provider | default('') | lower == 'gcp' -# Azure Blob Storage (if 'provision=azure') +# Azure Blob Storage (if 'cloud_provider=azure') - name: "Set variable 'wal_g_json' for backup in Azure Blob Storage" ansible.builtin.set_fact: wal_g_json: @@ -87,9 +87,9 @@ - { option: "PGPORT", value: "{{ postgresql_port | default('5432') }}" } - { option: "PGUSER", value: "{{ patroni_superuser_username | default('postgres') }}" } no_log: true # do not output contents to the ansible log - when: provision | default('') | lower == 'azure' + when: cloud_provider | default('') | lower == 'azure' -# DigitalOcean Spaces Object Storage (if 'provision=digitalocean') +# DigitalOcean Spaces Object Storage (if 'cloud_provider=digitalocean') - name: "Set variable 'wal_g_json' for backup in DigitalOcean Spaces Object Storage" ansible.builtin.set_fact: wal_g_json: @@ -109,6 +109,6 @@ - { option: "PGPORT", value: "{{ postgresql_port | default('5432') }}" } - { option: "PGUSER", value: "{{ patroni_superuser_username | default('postgres') }}" } no_log: true # do not output contents to the ansible log - when: provision | default('') | lower == 'digitalocean' + when: cloud_provider | default('') | lower == 'digitalocean' ... diff --git a/roles/wal-g/tasks/main.yml b/roles/wal-g/tasks/main.yml index 35720fd5b..20807ac12 100644 --- a/roles/wal-g/tasks/main.yml +++ b/roles/wal-g/tasks/main.yml @@ -1,9 +1,9 @@ --- # Automatic setup of the backup configuration based on the selected cloud provider. -# if 'provision' is 'aws', 'gcp', 'azure', 'digitalocean'. +# if 'cloud_provider' is 'aws', 'gcp', 'azure', 'digitalocean'. - ansible.builtin.import_tasks: auto_conf.yml - when: provision | default('none') != 'none' + when: cloud_provider | default('') | length > 0 tags: wal-g, wal_g, wal_g_conf - name: Check if WAL-G is already installed diff --git a/vars/Debian.yml b/vars/Debian.yml index ec0547dcb..21c117a75 100644 --- a/vars/Debian.yml +++ b/vars/Debian.yml @@ -2,7 +2,7 @@ # PostgreSQL variables postgresql_cluster_name: "\ - {% if provision is defined and provision | lower != 'none' %}\ + {% if cloud_provider | default('') | length > 0 %}\ {{ patroni_cluster_name }}\ {% else %}\ main\ @@ -12,7 +12,7 @@ postgresql_cluster_name: "\ # along the path defined in the 'pg_data_mount_path' variable (or use '/pgdata' by default). # You can specify custom data dir path. Example: "/pgdata/{{ postgresql_version }}/{{ postgresql_cluster_name }}" postgresql_data_dir: "\ - {% if provision is defined and provision | lower != 'none' %}\ + {% if cloud_provider | default('') | length > 0 %}\ {{ pg_data_mount_path | default('/pgdata') }}/{{ postgresql_version }}/{{ postgresql_cluster_name }}\ {% else %}\ /var/lib/postgresql/{{ postgresql_version }}/{{ postgresql_cluster_name }}\ diff --git a/vars/RedHat.yml b/vars/RedHat.yml index b20c30910..58f9a1297 100644 --- a/vars/RedHat.yml +++ b/vars/RedHat.yml @@ -6,7 +6,7 @@ # along the path defined in the 'pg_data_mount_path' variable (or use '/pgdata' by default). # You can specify custom data dir path. Example: "/pgdata/{{ postgresql_version }}/{{ patroni_cluster_name }}" postgresql_data_dir: "\ - {% if provision is defined and provision | lower != 'none' %}\ + {% if cloud_provider | default('') | length > 0 %}\ {{ pg_data_mount_path | default('/pgdata') }}/{{ postgresql_version }}/{{ patroni_cluster_name }}\ {% else %}\ /var/lib/pgsql/{{ postgresql_version }}/data\