diff --git a/Ansible/ansible_collections/jfrog/platform/roles/postgres/defaults/main.yml b/Ansible/ansible_collections/jfrog/platform/roles/postgres/defaults/main.yml index 9a729efb..5e1b2593 100644 --- a/Ansible/ansible_collections/jfrog/platform/roles/postgres/defaults/main.yml +++ b/Ansible/ansible_collections/jfrog/platform/roles/postgres/defaults/main.yml @@ -1,108 +1,203 @@ -# Default version of Postgres server to install. -postgres_version: 13 - -# Default listen_addresses of Postgres server -postgres_listen_addresses: 0.0.0.0 - -# Default port of Postgres server -postgres_port: 5432 - -# Location of GPG key used to sign the RPMs -postgres_rpmkey_url: "https://download.postgresql.org/pub/repos/yum/keys/PGDG-RPM-GPG-KEY-RHEL" - -# Server version in package: -postgres_server_pkg_version: "{{ postgres_version | replace('.', '') }}" - -# Whether or not the files are on ZFS. -postgres_server_volume_is_zfs: false - -# Postgres setting max_connections. -postgres_server_max_connections: 1000 - -# Postgres setting shared_buffers. -postgres_server_shared_buffers: 128MB - -# Postgres setting maintenance_work_mem. -postgres_server_maintenance_work_mem: 64MB - -# Postgres setting effective_io_concurrency. -postgres_server_effective_io_concurrency: 1 - -# Postgres setting max_worker_processes. -postgres_server_max_worker_processes: 8 - -# Postgres setting max_parallel_maintenance_workers. -postgres_server_max_parallel_maintenance_workers: 2 - -# Postgres setting max_parallel_workers_per_gather. -postgres_server_max_parallel_workers_per_gather: 2 - -# Postgres setting parallel_leader_participation. -postgres_server_parallel_leader_participation: true - -# Postgres setting max_parallel_workers. -postgres_server_max_parallel_workers: 8 - -# Postgres setting max_locks_per_transaction. -postgres_server_max_locks_per_transaction: 64 - -# Configuration for "random access" cost. -postgres_server_random_page_cost: "4.0" - -# User name that the postgres user runs as. -postgres_user: postgres - -postgres_locale: "en_US.UTF-8" -# Whether or not to lock checkpoints. -postgres_server_log_checkpoints: false - -# Whether or not to lock connects. -postgres_server_log_connections: false - -# Whether or not to lock disconnects. -postgres_server_log_disconnections: false - -# Whether or not to log duration -postgres_server_log_duration: false - -# Error logging verbosity. -postgres_server_log_error_verbosity: "default" - -# Whether or not to log the host name. -postgres_server_log_hostname: false - -# Whether or not to lock waits. -postgres_server_log_lock_waits: false - -# Which statements to log. -postgres_server_log_statements: "none" - -# Whether or not to enable the auto_explain module. -postgres_server_auto_explain_enabled: false - -# Minimal duration to log auto explain for. -postgres_server_auto_explain_log_min_duration: -1 - -# Whether or not to use EXPLAIN ANALYZE. -postgres_server_auto_explain_log_analyze: true - -# Sets the hosts that can access the database -postgres_allowed_hosts: - - { - type: "host", - database: "all", - user: "all", - address: "0.0.0.0/0", - method: "trust", - } - -# PostgreSQL misc settings -postgresql_bin_path: "{{ default_postgresql_bin_path }}" -postgresql_config_path: "{{ default_postgresql_config_path }}" -postgresql_data_dir: "{{ default_postgresql_data_dir }}" -postgresql_daemon: "{{ default_postgresql_daemon }}" -postgresql_external_pid_file: "{{ default_postgresql_external_pid_file }}" - -postgres_apt_key_id: "{{ default_postgres_apt_key_id }}" -postgres_apt_key_url: "{{ default_postgres_apt_key_url }}" -postgres_apt_repository_repo: "{{ default_postgres_apt_repository_repo }}" +--- +# Defaults file for postgres + +# Postgres version to install (default: 13) +postgresql_version: '13' + +# Set to true if you want to use PostgreSQL official repository (default: false) +# By design this role installs PostgreSQL included with the distribution. +postgresql_use_official_repos: false + +# Define PostgreSQL user/group (default: postgres) +postgresql_user: postgres +postgresql_group: postgres + +# PostgreSQL Password Authentication method +# https://www.postgresql.org/docs/current/auth-password.html +# `md5` or `scram-sha-256` (md5 is deprecated) +postgresql_auth_method: 'scram-sha-256' + +# Define the locales for PostgreSQL databases. +postgresql_locale: 'en_US.UTF-8' + +# Host based authentication (hba) entries to be added to the pg_hba.conf. This +# variable's defaults reflect the defaults that come with a fresh installation. +postgresql_hba_entries: + - {type: local, database: all, user: postgres, auth_method: peer} + - {type: local, database: all, user: all, auth_method: peer} + - {type: host, database: all, user: all, address: '127.0.0.1/32', auth_method: "{{ postgresql_auth_method }}"} + - {type: host, database: all, user: all, address: '::1/128', auth_method: "{{ postgresql_auth_method }}"} +# - {type: host, database: all, user: all, address: '0.0.0.0/0', auth_method: trust } + +# Whether to output user data when managing users. +postgres_users_no_log: true + +# Base configuration option that will be set by default. +# Any of these can be overriden in `postgresql_custom_config_options` +postgresql_default_config_options: + - option: 'unix_socket_directories' + value: "{{ postgresql_unix_socket_directories | join(',') }}" + - option: 'external_pid_file' + value: "{{ postgresql_external_pid_file }}" + - option: 'max_connections' + value: '1000' + +# Custom configuration options that will be set in postgresql.conf. +# For logging option refer to: https://www.postgresql.org/docs/current/runtime-config-logging.html +postgresql_custom_config_options: [] + +# Example below to configure a total of 1GB per week of logs +# Ensure you set postgresql_add_logrotate to true +# Compatible with pgbadger + +# postgresql_custom_config_options: +# - option: 'logging_collector' +# value: 'on' +# - option: 'log_directory' +# value: '/var/log/postgresql' +# - option: 'log_filename' +# value: 'postgresql-%Y%m%d%H%M%S.log' +# - option: 'log_file_mode' +# value: '0600' +# - option: 'log_truncate_on_rotation' +# value: 'on' +# - option: 'log_rotation_age' +# value: '1d' +# - option: 'log_rotation_size' +# value: '143000' +# - option: 'log_line_prefix' +# value: '%t [%p]: db=%d,user=%u,app=%a,client=%h ' +# - option: 'log_min_duration_statement' +# value: '0' +# - option: 'log_checkpoints' +# value: 'on' +# - option: 'log_connections' +# value: 'on' +# - option: 'log_disconnections' +# value: 'on' +# - option: 'log_lock_waits' +# value: 'on' +# - option: 'log_temp_files' +# value: '0' +# - option: 'log_autovacuum_min_duration' +# value: '0' +# - option: 'log_error_verbosity' +# value: 'default' + +# Set to true if you want to add logrotate option. +# Will be applied if log_directory is not a relative path+. +postgresql_add_logrotate: false +postgresql_logrotate_content: | + {{ postgresql_effective_log_dir }}/*.log { + hourly + missingok + rotate 7 + compress + delaycompress + notifempty + nocreate + } + +# Postgresql users and databases default configuration +# Every setting can be overwritten by providing the `artifactory_db_name` or similar +postgresql_databases_users: + + artifactory: + name: "{{ artifactory_db_name | d('artifactory') }}" + username: "{{ artifactory_db_user_name | d('artifactory') }}" + userpass: "{{ artifactory_db_user_pass | d('yRQBPdbTsYVd9MFqBBnbrh') }}" + userpass_encrypted: "{{ artifactory_db_user_pass_encrypted | d('true') }}" + userprivs: "{{ artifactory_db_user_privs | d(['ALL']) }}" + owner: "{{ artifactory_db_owner | d(postgresql_databases.artifactory.user) }}" + lc_collate: "{{ artifactory_db_lc_collate | d(postgresql_locale) }}" + lc_ctype: "{{ artifactory_db_lc_ctype | d(postgresql_locale) }}" + encoding: "{{ artifactory_db_encoding | d('UTF-8') }}" + template: "{{ artifactory_db_template | d('template0') }}" + login_host: "{{ artifactory_db_login_host | d('localhost') }}" + login_port: "{{ artifactory_db_login_port | d(null) }}" + login_user: "{{ artifactory_db_login_user | d(postgresql_user) }}" + login_password: "{{ artifactory_db_login_password | d(null) }}" + login_unix_socket: "{{ artifactory_db_unix_socket | d(null) }}" + state: "{{ artifactory_db_state | d(artifactory_enabled | d(true) | bool | ternary('present', 'absent')) }}" + driver: "{{ artifactory_db_driver | d('org.postgresql.Driver') }}" + url: >- + jdbc:postgresql:// + {{ (hostvars[groups['postgres_servers'][0]].ansible_host | d(hostvars[groups['postgres_servers'][0]].ansible_default_ipv4.address | d('127.0.0.1'))) }}: + {{ artifactory_db_login_port | d('5432') }}/ + {{ artifactory_db_name | d('artifactory') }}?sslmode=disable + + xray: + name: "{{ xray_db_name | d('xray') }}" + username: "{{ xray_db_user_name | d('xray') }}" + userpass: "{{ xray_db_user_pass | d('mYT5izjC4XkDmafv7wUbs4') }}" + userpass_encrypted: "{{ xray_db_user_pass_encrypted | d('true') }}" + userprivs: "{{ xray_db_user_privs | d(['ALL']) }}" + owner: "{{ xray_db_owner | d(postgresql_databases.xray.user) }}" + lc_collate: "{{ xray_db_lc_collate | d(postgresql_locale) }}" + lc_ctype: "{{ xray_db_lc_ctype | d(postgresql_locale) }}" + encoding: "{{ xray_db_encoding | d('UTF-8') }}" + template: "{{ xray_db_template | d('template0') }}" + login_host: "{{ xray_db_login_host | d(null) }}" + login_port: "{{ xray_db_login_port | d(null) }}" + login_user: "{{ xray_db_login_user | d(postgresql_user) }}" + login_password: "{{ xray_db_login_password | d(null) }}" + login_unix_socket: "{{ xray_db_unix_socket | d(null) }}" + state: "{{ xray_db_state | d(xray_enabled | d(true) | bool | ternary('present', 'absent')) }}" + driver: "{{ xray_db_driver | d('org.postgresql.Driver') }}" + url: >- + jdbc:postgresql:// + {{ (hostvars[groups['postgres_servers'][0]].ansible_host | d(hostvars[groups['postgres_servers'][0]].ansible_default_ipv4.address | d('127.0.0.1'))) }}: + {{ xray_db_login_port | d('5432') }}/ + {{ xray_db_name | d('xray') }}?sslmode=disable + + distribution: + name: "{{ distribution_db_name | d('distribution') }}" + username: "{{ distribution_db_user_name | d('distribution') }}" + userpass: "{{ distribution_db_user_pass | d('XSaP2U8BSCAmLrek4Hb7Vx') }}" + userpass_encrypted: "{{ distribution_db_user_pass_encrypted | d('true') }}" + userprivs: "{{ distribution_db_user_privs | d(['ALL']) }}" + owner: "{{ distribution_db_owner | d(postgresql_users.distribution.user) }}" + lc_collate: "{{ distribution_db_lc_collate | d(postgresql_locale) }}" + lc_ctype: "{{ distribution_db_lc_ctype | d(postgresql_locale) }}" + encoding: "{{ distribution_db_encoding | d('UTF-8') }}" + template: "{{ distribution_db_template | d('template0') }}" + login_host: "{{ distribution_db_login_host | d(null) }}" + login_port: "{{ distribution_db_login_port | d(null) }}" + login_user: "{{ distribution_db_login_user | d(postgresql_user) }}" + login_password: "{{ distribution_db_login_password | d(null) }}" + login_unix_socket: "{{ distribution_db_unix_socket | d(null) }}" + state: "{{ distribution_db_state | d(distribution_db_state | d(true) | bool | ternary('present', 'absent')) }}" + driver: "{{ distribution_db_driver | d('org.postgresql.Driver') }}" + url: >- + jdbc:postgresql:// + {{ (hostvars[groups['postgres_servers'][0]].ansible_host | d(hostvars[groups['postgres_servers'][0]].ansible_default_ipv4.address | d('127.0.0.1'))) }}: + {{ distribution_db_login_port | d('5432') }}/ + {{ distribution_db_name | d('distribution') }}?sslmode=disable + + insight: + name: "{{ insight_db_name | d('insight') }}" + username: "{{ insight_db_user_name | d('insight') }}" + userpass: "{{ insight_db_user_pass | d('JJ49gTYWzFA5psTjyy5bFu') }}" + userpass_encrypted: "{{ insight_db_user_pass_encrypted | d('true') }}" + userprivs: "{{ insight_db_user_privs | d(['ALL']) }}" + owner: "{{ insight_db_owner | d(postgresql_users.insight.user) }}" + lc_collate: "{{ insight_db_lc_collate | d(postgresql_locale) }}" + lc_ctype: "{{ insight_db_lc_ctype | d(postgresql_locale) }}" + encoding: "{{ insight_db_encoding | d('UTF-8') }}" + template: "{{ insight_db_template | d('template0') }}" + login_host: "{{ insight_db_login_host | d(null) }}" + login_port: "{{ insight_db_login_port | d(null) }}" + login_user: "{{ insight_db_login_user | d(postgresql_user) }}" + login_password: "{{ insight_db_login_password | d(null) }}" + login_unix_socket: "{{ insight_db_unix_socket | d(null) }}" + state: "{{ insight_db_state | d(insight_enabled | d(true) | bool | ternary('present', 'absent')) }}" + driver: "{{ insight_db_driver | d('org.postgresql.Driver') }}" + url: >- + jdbc:postgresql:// + {{ (hostvars[groups['postgres_servers'][0]].ansible_host | d(hostvars[groups['postgres_servers'][0]].ansible_default_ipv4.address | d('127.0.0.1'))) }}: + {{ insight_db_login_port | d('5432') }}/ + {{ insight_db_name | d('insight') }}?sslmode=disable + +# RHEL/CentOS only. Define repositories to enable/disable for PostgreSQL installation. +postgresql_install_enablerepo: [] +postgresql_install_disablerepo: [] diff --git a/Ansible/ansible_collections/jfrog/platform/roles/postgres/handlers/main.yml b/Ansible/ansible_collections/jfrog/platform/roles/postgres/handlers/main.yml index 1bcf0b6b..aa6bb4b3 100644 --- a/Ansible/ansible_collections/jfrog/platform/roles/postgres/handlers/main.yml +++ b/Ansible/ansible_collections/jfrog/platform/roles/postgres/handlers/main.yml @@ -1,6 +1,6 @@ ---- -- name: Restart postgresql - become: true - ansible.builtin.systemd: - name: "{{ postgresql_daemon }}" - state: restarted +--- +- name: Restart PostgreSQL + become: true + ansible.builtin.systemd_service: + name: "{{ postgresql_daemon }}" + state: restarted diff --git a/Ansible/ansible_collections/jfrog/platform/roles/postgres/meta/main.yml b/Ansible/ansible_collections/jfrog/platform/roles/postgres/meta/main.yml index 4f95878e..8d58fde2 100644 --- a/Ansible/ansible_collections/jfrog/platform/roles/postgres/meta/main.yml +++ b/Ansible/ansible_collections/jfrog/platform/roles/postgres/meta/main.yml @@ -1,27 +1,28 @@ ---- -dependencies: [] - -galaxy_info: - author: "JFrog Maintainers Team " - description: "The postgres role will install Postgresql software and configure a database and user to support an Artifactory or Xray server." - company: JFrog - issue_tracker_url: "https://github.com/jfrog/JFrog-Cloud-Installers/issues" - license: license (Apache-2.0) - min_ansible_version: 2.9 - platforms: - - name: EL - versions: - - 7 - - 8 - - name: Ubuntu - versions: - - bionic - - focal - - jammy - - name: Debian - versions: - - buster - - bullseye - galaxy_tags: - - postgres - - jfrog +--- +dependencies: [] + +galaxy_info: + author: "JFrog Maintainers Team " + description: "The postgres role will install Postgresql software and configure a database and user to support an Artifactory or Xray server." + company: JFrog + issue_tracker_url: "https://github.com/jfrog/JFrog-Cloud-Installers/issues" + license: 'license (Apache-2.0)' + min_ansible_version: '2.9' + platforms: + - name: EL + versions: + - '8' + - '9' + - name: Ubuntu + versions: + - bionic + - focal + - jammy + - noble + - name: Debian + versions: + - buster + - bullseye + galaxy_tags: + - postgres + - jfrog diff --git a/Ansible/ansible_collections/jfrog/platform/roles/postgres/tasks/Debian.yml b/Ansible/ansible_collections/jfrog/platform/roles/postgres/tasks/Debian.yml deleted file mode 100644 index ee3fb8fa..00000000 --- a/Ansible/ansible_collections/jfrog/platform/roles/postgres/tasks/Debian.yml +++ /dev/null @@ -1,48 +0,0 @@ -- name: Install prerequisite packages - become: true - ansible.builtin.apt: - name: ['acl', 'apt-transport-https', 'locales', 'python3-psycopg2'] - state: present - update_cache: true - -- name: Ensure UTF-8 locale exists - become: true - community.general.locale_gen: - name: en_US.UTF-8 - state: present - -- name: Import PostgreSQL repository key - become: true - ansible.builtin.apt_key: - url: "{{ postgres_apt_key_url }}" - id: "{{ postgres_apt_key_id }}" - state: present - register: download_postgresql_key - until: download_postgresql_key is success - retries: 3 - delay: 3 - -- name: Register PostgreSQL repository - become: true - ansible.builtin.apt_repository: - repo: "{{ postgres_apt_repository_repo }}" - state: present - filename: pgdg - register: download_postgresql_repo - until: download_postgresql_repo is success - retries: 3 - delay: 3 - -- name: Install postgres packages - become: true - ansible.builtin.apt: - name: - - postgresql-{{ postgres_version }} - - postgresql-contrib-{{ postgres_version }} - state: present - update_cache: true - cache_valid_time: 3600 - register: download_postgresql - until: download_postgresql is success - retries: 3 - delay: 3 diff --git a/Ansible/ansible_collections/jfrog/platform/roles/postgres/tasks/RedHat.yml b/Ansible/ansible_collections/jfrog/platform/roles/postgres/tasks/RedHat.yml deleted file mode 100644 index 110ebf34..00000000 --- a/Ansible/ansible_collections/jfrog/platform/roles/postgres/tasks/RedHat.yml +++ /dev/null @@ -1,88 +0,0 @@ -- name: Install prerequisite packages - become: true - ansible.builtin.yum: - name: - - acl - - sudo - - wget - - perl - state: present - -- name: Install python3-psycopg2 - become: true - ansible.builtin.yum: - name: python3-psycopg2 - state: present - when: ansible_distribution_major_version == '8' - -- name: Install python2-psycopg2 - become: true - ansible.builtin.yum: - name: python-psycopg2 - state: present - when: ansible_distribution_major_version == '7' - -- name: Fixup some locale issues - become: true - ansible.builtin.lineinfile: - dest: /etc/locale.conf - line: "{{ item }}" - state: present - create: true - mode: 0644 - loop: - - LANG=en_us.UTF-8 - - LANGUAGE=en_us.UTF-8 - -- name: Import PostgreSQL GPG public key - become: true - ansible.builtin.rpm_key: - key: "{{ postgres_rpmkey_url }}" - state: present - register: download_postgresql_key - until: download_postgresql_key is success - retries: 3 - delay: 3 - -- name: Install PostgreSQL repository - become: true - ansible.builtin.yum: - name: "{{ base }}/reporpms/EL-{{ version }}-x86_64/{{ repo_file_name }}" - state: present - vars: - base: https://download.postgresql.org/pub/repos/yum - version: "{{ ansible_distribution_major_version }}" - repo_file_name: pgdg-redhat-repo-latest.noarch.rpm - register: download_postgresql_repo - until: download_postgresql_repo is success - retries: 3 - delay: 3 - -- name: Disable PostgreSQL module - become: true - ansible.builtin.copy: - dest: /etc/dnf/modules.d/postgresql.module - owner: root - group: root - mode: 0644 - content: | - [postgresql] - name=postgresql - stream= - profiles= - state=disabled - when: - - ansible_os_family == 'RedHat' - - ansible_distribution_major_version | int == 8 - -- name: Install PostgreSQL packages - become: true - ansible.builtin.yum: - name: - - postgresql{{ postgres_server_pkg_version }}-server - - postgresql{{ postgres_server_pkg_version }}-contrib - state: present - register: download_postgresql - until: download_postgresql is success - retries: 3 - delay: 3 diff --git a/Ansible/ansible_collections/jfrog/platform/roles/postgres/tasks/configure.yml b/Ansible/ansible_collections/jfrog/platform/roles/postgres/tasks/configure.yml new file mode 100644 index 00000000..fccaa9b8 --- /dev/null +++ b/Ansible/ansible_collections/jfrog/platform/roles/postgres/tasks/configure.yml @@ -0,0 +1,93 @@ +--- +- name: Set PostgreSQL environment variables + become: true + ansible.builtin.template: + src: postgres.sh.j2 + dest: /etc/profile.d/postgres.sh + mode: '0644' + notify: Restart PostgreSQL + +- name: Convert postgresql_default_config_options to dictionary + ansible.builtin.set_fact: + __dict_postgresql_default_config_options: "{{ postgresql_default_config_options | items2dict(key_name='option', value_name='value') }}" + +- name: Convert postgresql_custom_config_options to dictionary + ansible.builtin.set_fact: + __dict_postgresql_custom_config_options: "{{ postgresql_custom_config_options | items2dict(key_name='option', value_name='value') }}" + +- name: Merge PostgreSQL configuration options + ansible.builtin.set_fact: + __dict_postgresql_config_options: "{{ __dict_postgresql_default_config_options | combine(__dict_postgresql_custom_config_options) }}" + +- name: Define postgresql_effective_log_dir, if log_directory is absolute + ansible.builtin.set_fact: + postgresql_effective_log_dir: "{{ __dict_postgresql_config_options['log_directory'] }}" + when: __dict_postgresql_config_options['log_directory'] is match('^/') + +- name: Define postgresql_effective_log_dir, if log_directory is relative + ansible.builtin.set_fact: + postgresql_effective_log_dir: "{{ postgresql_data_dir }}/{{ __dict_postgresql_config_options['log_directory'] }}" + when: __dict_postgresql_config_options['log_directory'] is not match('^/') + +- name: Ensure PostgreSQL log directory exists + become: true + ansible.builtin.file: + path: "{{ postgresql_effective_log_dir }}" + owner: "{{ postgresql_user }}" + group: "{{ postgresql_group }}" + state: directory + mode: '0700' + when: + - postgresql_effective_log_dir is defined + - postgresql_effective_log_dir | length > 0 + +- name: Ensure PostgreSQL log rotation is configured + become: true + ansible.builtin.copy: + content: "{{ postgresql_logrotate_content }}" + dest: "{{ logrotate_dir | d('/etc/logrotate.d') }}/postgresql" + owner: root + group: root + mode: '0644' + when: + - postgresql_add_logrotate | d(false) | bool + - postgresql_logrotate_content | d('') | length > 0 + - __dict_postgresql_config_options['log_directory'] is not match('^/') + +- name: Ensure PostgreSQL unix socket directories exist + become: true + ansible.builtin.file: + path: "{{ item }}" + state: directory + owner: "{{ postgresql_user }}" + group: "{{ postgresql_group }}" + mode: '0755' + loop: "{{ __dict_postgresql_config_options['unix_socket_directories'].split(',') }}" + when: + - __dict_postgresql_config_options['unix_socket_directories'] is defined + - __dict_postgresql_config_options['unix_socket_directories'] | length > 0 + +- name: Configure global settings + become: true + ansible.builtin.lineinfile: + dest: "{{ postgresql_config_file }}" + regexp: "^#?{{ item.option }}.+$" + line: "{{ item.option }} = '{{ item.value }}'" + state: "{{ item.state | default('present') }}" + mode: '0644' + loop: "{{ postgresql_default_config_options + postgresql_custom_config_options }}" + notify: Restart PostgreSQL + +- name: Configure host based authentication + become: true + ansible.builtin.template: + src: 'pg_hba.conf.j2' + dest: "{{ postgresql_config_dir }}/pg_hba.conf" + owner: "{{ postgresql_user }}" + group: "{{ postgresql_group }}" + mode: '0600' + notify: Restart PostgreSQL + when: postgresql_hba_entries | d([]) | length > 0 + +- name: Flush all handlers + ansible.builtin.meta: flush_handlers diff --git a/Ansible/ansible_collections/jfrog/platform/roles/postgres/tasks/initialize.yml b/Ansible/ansible_collections/jfrog/platform/roles/postgres/tasks/initialize.yml new file mode 100644 index 00000000..ff629801 --- /dev/null +++ b/Ansible/ansible_collections/jfrog/platform/roles/postgres/tasks/initialize.yml @@ -0,0 +1,29 @@ +--- +- name: Ensure PostgreSQL data directory exists. + become: true + ansible.builtin.file: + path: "{{ postgresql_data_dir }}" + owner: "{{ postgresql_user }}" + group: "{{ postgresql_group }}" + state: directory + mode: '0700' + +- name: Check if PostgreSQL configuration exist + become: true + ansible.builtin.stat: + path: "{{ postgresql_config_file }}" + register: __stdo_postgresql_conf + +- name: Check if PostgreSQL database is already initialized. + become: true + ansible.builtin.stat: + path: "{{ postgresql_data_dir }}/PG_VERSION" + register: __stdo_pgdata_dir_version + +- name: Ensure PostgreSQL database is initialized. + become: true + become_user: "{{ postgresql_user }}" + ansible.builtin.command: "{{ postgresql_bin_path }}/initdb --locale={{ postgresql_locale }} --pgdata={{ postgresql_data_dir }}" + when: not __stdo_postgresql_conf.stat.exists or not __stdo_pgdata_dir_version.stat.exists + args: + creates: "{{ postgresql_data_dir }}/PG_VERSION" diff --git a/Ansible/ansible_collections/jfrog/platform/roles/postgres/tasks/install.yml b/Ansible/ansible_collections/jfrog/platform/roles/postgres/tasks/install.yml deleted file mode 100644 index 9ab5d2d3..00000000 --- a/Ansible/ansible_collections/jfrog/platform/roles/postgres/tasks/install.yml +++ /dev/null @@ -1,137 +0,0 @@ -- name: Assert database username and password are defined - ansible.builtin.assert: - that: - - curr_user.username is defined - - curr_user.password is defined - loop: "{{ database | dict2items | map(attribute='value') | list }}" - loop_control: - loop_var: curr_user - when: curr_user.enabled | bool - no_log: true # secret passwords - -- name: Define OS-specific variables - ansible.builtin.include_vars: "{{ ansible_os_family }}.yml" - -- name: Install prerequisite packages - ansible.builtin.include_tasks: "{{ ansible_os_family }}.yml" - -- name: Set PostgreSQL environment variables - become: true - ansible.builtin.template: - src: postgres.sh.j2 - dest: /etc/profile.d/postgres.sh - mode: 0644 - notify: Restart postgresql - -- name: Ensure PostgreSQL data directory exists - become: true - ansible.builtin.file: - path: "{{ postgresql_data_dir }}" - owner: postgres - group: postgres - state: directory - mode: 0700 - -- name: Initialize PostgreSQL database cluster - become: true - become_user: postgres - ansible.builtin.command: "{{ postgresql_bin_path }}/initdb -D {{ postgresql_data_dir }}" - args: - creates: "{{ postgresql_data_dir }}/PG_VERSION" - environment: - LC_ALL: "{{ postgres_locale }}" - -- name: Check FIPS status - ansible.builtin.command: cat /proc/sys/crypto/fips_enabled - register: _fips_enabled - ignore_errors: true - changed_when: false - -- name: Setup postgres configuration files - become: true - become_user: postgres - ansible.builtin.template: - src: "{{ item }}.j2" - dest: "{{ postgresql_config_path }}/{{ item }}" - owner: postgres - group: postgres - mode: 0644 - loop: - - pg_hba.conf - - postgresql.conf - notify: Restart postgresql - -- name: Setup postgres systemd overide directory - become: true - ansible.builtin.file: - path: "/etc/systemd/system/postgresql-{{ postgres_version }}.service.d" - state: directory - owner: root - group: root - mode: 0755 - -- name: Setup postgres systemd overides - become: true - ansible.builtin.template: - src: override.conf.j2 - dest: "/etc/systemd/system/postgresql-{{ postgres_version }}.service.d/override.conf" - owner: root - group: root - mode: 0644 - -- name: Ensure PostgreSQL is started and enabled on boot - become: true - ansible.builtin.systemd: - name: "{{ postgresql_daemon }}" - state: started - enabled: true - -- name: Hold until Postgresql is up and running - ansible.builtin.wait_for: - port: "{{ postgres_port }}" - timeout: 120 - sleep: 10 - -- name: Create user - become: true - become_user: postgres - community.postgresql.postgresql_user: - name: "{{ curr_user.username }}" - password: "{{ curr_user.password }}" - conn_limit: "-1" - loop: "{{ database | dict2items | map(attribute='value') | list }}" - loop_control: - loop_var: curr_user - when: curr_user.enabled | bool - no_log: true # secret passwords - -- name: Create database - become: true - become_user: postgres - community.postgresql.postgresql_db: - name: "{{ curr_db.name }}" - owner: "{{ curr_db.owner }}" - encoding: UTF-8 - lc_collate: "{{ postgres_locale }}" - lc_ctype: "{{ postgres_locale }}" - template: template0 - loop: "{{ database | dict2items | map(attribute='value') | list }}" - loop_control: - loop_var: curr_db - when: curr_db.enabled | bool - no_log: true # secret passwords - -- name: Grant privs on db - become: true - become_user: postgres - community.postgresql.postgresql_privs: - database: "{{ curr_db.name }}" - role: "{{ curr_db.owner }}" - state: present - privs: ALL - type: database - loop: "{{ database | dict2items | map(attribute='value') | list }}" - loop_control: - loop_var: curr_db - when: curr_db.enabled | bool - no_log: true # secret passwords diff --git a/Ansible/ansible_collections/jfrog/platform/roles/postgres/tasks/install/debian.yml b/Ansible/ansible_collections/jfrog/platform/roles/postgres/tasks/install/debian.yml new file mode 100644 index 00000000..304c5aef --- /dev/null +++ b/Ansible/ansible_collections/jfrog/platform/roles/postgres/tasks/install/debian.yml @@ -0,0 +1,59 @@ +--- +- name: Configure PostgreSQL repositories + when: artifactory_postgresql_use_official_repos | bool + block: + + - name: Import PostgreSQL repository signing key + become: true + ansible.builtin.apt_key: + url: "{{ postgresql_repo_key_url }}" + id: "{{ postgresql_repo_key_id }}" + state: present + + - name: Add PostgreSQL repository + become: true + ansible.builtin.apt_repository: + repo: "{{ postgres_apt_repository_repo }}" + state: present + filename: pgdg + +- name: Ensure locales are present + become: true + community.general.locale_gen: + name: "{{ postgresql_locale }}" + state: present + register: locale_update_result + +- name: Install PostgreSQL Python libraries + become: true + ansible.builtin.apt: + name: "{{ postgresql_python_library }}" + state: present + update_cache: true + cache_valid_time: 3600 + when: + - postgresql_python_library is defined + - postgresql_python_library | length > 0 + +- name: Install PostgreSQL Server packages + become: true + ansible.builtin.apt: + name: "{{ postgresql_packages }}" + state: present + register: postgresql_install_result + +- name: Force-restart PostgreSQL if locales changed + become: true + ansible.builtin.systemd_service: + name: "{{ postgresql_daemon }}" + state: restarted + when: + - locale_update_result.changed + - not postgresql_install_result.changed + +- name: Ensure PostgreSQL service is started and enabled + become: true + ansible.builtin.systemd_service: + name: "{{ postgresql_daemon }}" + state: started + enabled: true diff --git a/Ansible/ansible_collections/jfrog/platform/roles/postgres/tasks/install/redhat.yml b/Ansible/ansible_collections/jfrog/platform/roles/postgres/tasks/install/redhat.yml new file mode 100644 index 00000000..fca301b3 --- /dev/null +++ b/Ansible/ansible_collections/jfrog/platform/roles/postgres/tasks/install/redhat.yml @@ -0,0 +1,90 @@ +--- +- name: Configure PostgreSQL repositories + when: artifactory_postgresql_use_official_repos | bool + block: + + - name: Import PostgreSQL signing key + become: true + ansible.builtin.rpm_key: + key: "{{ postgres_rpmkey_url }}" + state: present + + - name: Add PostgreSQL PDGD repo + become: true + ansible.builtin.dnf: + name: "{{ postgresql_repo_url }}" + state: present + + - name: Disable PostgreSQL module + become: true + ansible.builtin.copy: + dest: /etc/dnf/modules.d/postgresql.module + owner: root + group: root + mode: '0644' + content: | + [postgresql] + name=postgresql + stream= + profiles= + state=disabled + + - name: Update cache + become: true + ansible.builtin.dnf: + state: present + update_cache: true + when: ansible_facts['pkg_mgr'] == 'dnf' + +- name: Ensure locale settings are present + become: true + ansible.builtin.lineinfile: + path: /etc/locale.conf + regexp: "^{{ item.split('=')[0] }}=.*$" + line: "{{ item }}" + create: true + owner: root + group: root + mode: '0644' + state: present + loop: + - "LANG={{ postgresql_locale }}" + - "LANGUAGE={{ postgresql_locale }}" + register: locale_update_result + +- name: Install PostgreSQL Python libraries + become: true + ansible.builtin.dnf: + name: "{{ postgresql_python_library }}" + state: present + disablerepo: "{{ postgresql_install_disablerepo | d(omit, true) }}" + enablerepo: "{{ postgresql_install_enablerepo | d(omit, true) }}" + when: + - postgresql_python_library is defined + - postgresql_python_library | length > 0 + +- name: Install PostgreSQL packages + become: true + ansible.builtin.dnf: + name: "{{ postgresql_packages }}" + state: present + exclude: python-unversioned-command + disablerepo: "{{ postgresql_install_disablerepo | d(omit, true) }}" + enablerepo: "{{ postgresql_install_enablerepo | d(omit, true) }}" + register: postgresql_install_result + +- name: Force-restart PostgreSQL if locales changed + become: true + ansible.builtin.systemd_service: + name: "{{ postgresql_daemon }}" + state: restarted + when: + - locale_update_result.changed + - not postgresql_install_result.changed + +- name: Ensure PostgreSQL service is started and enabled + become: true + ansible.builtin.systemd_service: + name: "{{ postgresql_daemon }}" + state: started + enabled: true diff --git a/Ansible/ansible_collections/jfrog/platform/roles/postgres/tasks/main.yml b/Ansible/ansible_collections/jfrog/platform/roles/postgres/tasks/main.yml index 6e95fb86..b2e380f9 100644 --- a/Ansible/ansible_collections/jfrog/platform/roles/postgres/tasks/main.yml +++ b/Ansible/ansible_collections/jfrog/platform/roles/postgres/tasks/main.yml @@ -1,3 +1,62 @@ -- name: Install postgres - ansible.builtin.include_tasks: "install.yml" - when: postgres_enabled | bool +--- +- name: Gather system facts + ansible.builtin.setup: + +- name: Assert that we support the distribution + ansible.builtin.assert: + that: ansible_facts['os_family'] | lower in ['redhat', 'debian'] + fail_msg: 'Host is unsupported. Aborting.' + success_msg: 'Host is supported. Proceeding.' + quiet: true + +- name: Assert that Red Hat OS family is version 8+ + ansible.builtin.assert: + that: ansible_facts['distribution_major_version'] | int is version('8', '>=') + fail_msg: 'Host is unsupported. Aborting.' + success_msg: 'Host is supported. Proceeding.' + quiet: true + when: ansible_facts['os_family'] | lower == 'redhat' + +- name: Include global variables + ansible.builtin.include_vars: 'vars/all.yml' + +- name: Check if PostgreSQL version is supported on distribution + ansible.builtin.assert: + that: >- + postgresql_version | int in + os_family_postgresql_support_map[ + ansible_facts['distribution'] | lower + + ansible_facts['distribution_major_version'] + ] + success_msg: >- + PostgreSQL version {{ postgresql_version }} is supported on + {{ ansible_facts['distribution'] | lower }} + {{ ansible_facts['distribution_major_version'] }} + fail_msg: >- + PostgreSQL version {{ postgresql_version }} is not supported on + {{ ansible_facts['distribution'] | lower }} + {{ ansible_facts['distribution_major_version'] }} + quiet: false + when: artifactory_postgresql_use_official_repos | bool + +- name: Include distribution variables + ansible.builtin.include_vars: "{{ item }}" + with_first_found: + - "vars/{{ ansible_facts['distribution'] | lower }}.yml" + - "vars/{{ ansible_facts['os_family'] | lower }}.yml" + - "vars/default.yml" + +- name: Include tasks to install PostgreSQL + ansible.builtin.include_tasks: "{{ item }}" + with_first_found: + - "install/{{ ansible_facts['distribution'] | lower }}.yml" + - "install/{{ ansible_facts['os_family'] | lower }}.yml" + +- name: Include tasks to configure PostgreSQL settings + ansible.builtin.include_tasks: configure.yml + +- name: Include tasks to initialize PostgreSQL + ansible.builtin.include_tasks: initialize.yml + +- name: Include tasks to setup PostgreSQL users and databases + ansible.builtin.include_tasks: setup.yml diff --git a/Ansible/ansible_collections/jfrog/platform/roles/postgres/tasks/setup.yml b/Ansible/ansible_collections/jfrog/platform/roles/postgres/tasks/setup.yml new file mode 100644 index 00000000..1a5c3934 --- /dev/null +++ b/Ansible/ansible_collections/jfrog/platform/roles/postgres/tasks/setup.yml @@ -0,0 +1,52 @@ +--- +- name: Ensure PostgreSQL users are present + community.postgresql.postgresql_user: + name: "{{ item.value.username }}" + password: "{{ item.value.userpass }}" + encrypted: "{{ item.value.userpass_encrypted | d(omit) }}" + state: "{{ item.value.state }}" + login_host: "{{ item.value.login_host | d(omit) }}" + login_port: "{{ item.value.login_port | d(omit) }}" + login_user: "{{ item.value.login_user | d(omit) }}" + login_password: "{{ item.value.login_password | d(omit) }}" + login_unix_socket: "{{ item.value.login_unix_socket | d(omit) }}" + loop: "{{ lookup('ansible.builtin.dict', postgresql_databases_users) }}" + no_log: "{{ postgres_users_no_log }}" + become: true + become_user: "{{ postgresql_user }}" + environment: + PGOPTIONS: "{{ (postgresql_auth_method == 'scram-sha-256') | ternary('-c password_encryption=scram-sha-256', '') }}" + +- name: Ensure PostgreSQL databases are present + community.postgresql.postgresql_db: + name: "{{ item.value.name }}" + lc_collate: "{{ item.value.lc_collate }}" + lc_ctype: "{{ item.value.lc_ctype }}" + encoding: "{{ item.value.encoding }}" + template: "{{ item.value.template }}" + login_host: "{{ item.value.login_host | d(omit) }}" + login_port: "{{ item.value.login_port | d(omit) }}" + login_user: "{{ item.value.login_user | d(omit) }}" + login_password: "{{ item.value.login_password | d(omit) }}" + login_unix_socket: "{{ item.value.login_unix_socket | d(omit) }}" + state: "{{ item.value.state }}" + loop: "{{ lookup('ansible.builtin.dict', postgresql_databases_users) }}" + become: true + become_user: "{{ postgresql_user }}" + +- name: Ensure PostgreSQL users privileges are present + community.postgresql.postgresql_privs: + database: "{{ item.value.name }}" + state: "{{ item.value.state }}" + privs: "{{ item.value.userprivs }}" + roles: "{{ item.value.owner }}" + type: database + login_host: "{{ item.value.login_host | d(omit) }}" + login_port: "{{ item.value.login_port | d(omit) }}" + login_user: "{{ item.value.login_user | d(omit) }}" + login_password: "{{ item.value.login_password | d(omit) }}" + login_unix_socket: "{{ item.value.login_unix_socket | d(omit) }}" + loop: "{{ lookup('ansible.builtin.dict', postgresql_databases_users) }}" + no_log: "{{ postgres_users_no_log }}" + become: true + become_user: "{{ postgresql_user }}" diff --git a/Ansible/ansible_collections/jfrog/platform/roles/postgres/templates/override.conf.j2 b/Ansible/ansible_collections/jfrog/platform/roles/postgres/templates/override.conf.j2 deleted file mode 100644 index 62a2c454..00000000 --- a/Ansible/ansible_collections/jfrog/platform/roles/postgres/templates/override.conf.j2 +++ /dev/null @@ -1,3 +0,0 @@ -[Service] -Environment=PGDATA={{ postgresql_data_dir }} -Environment=LC_ALL={{ postgres_locale }} \ No newline at end of file diff --git a/Ansible/ansible_collections/jfrog/platform/roles/postgres/templates/pg_hba.conf.j2 b/Ansible/ansible_collections/jfrog/platform/roles/postgres/templates/pg_hba.conf.j2 index cb2f923a..53384159 100644 --- a/Ansible/ansible_collections/jfrog/platform/roles/postgres/templates/pg_hba.conf.j2 +++ b/Ansible/ansible_collections/jfrog/platform/roles/postgres/templates/pg_hba.conf.j2 @@ -1,18 +1,9 @@ -{{ ansible_managed | comment }} -# PostgreSQL Client Authentication Configuration File -# =================================================== -# -# See: https://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html - -# TYPE DATABASE USER ADDRESS METHOD -## localhost connections through Unix port (user name), IPv4, IPv6 (MD5 pw). -local all all peer -host all all 127.0.0.1/32 md5 -host all all ::1/128 md5 - -## remote connections IPv4 -{% if postgres_allowed_hosts and postgres_allowed_hosts is iterable -%} -{%- for host in postgres_allowed_hosts %} -{{ host.type | default('host') }} {{ host.database | default('all') }} {{ host.user | default('all') }} {{ host.address | default('0.0.0.0/0') }} {{ item.auth | default('trust') }} -{% endfor %} -{% endif %} +{{ ansible_managed | comment }} +# PostgreSQL Client Authentication Configuration File +# =================================================== +# +# See: https://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html + +{% for client in postgresql_hba_entries %} +{{ client.type }} {{ client.database }} {{ client.user }} {{ client.address|default('') }} {{ client.ip_address|default('') }} {{ client.ip_mask|default('') }} {{ client.auth_method }} {{ client.auth_options|default("") }} +{% endfor %} diff --git a/Ansible/ansible_collections/jfrog/platform/roles/postgres/templates/postgres.sh.j2 b/Ansible/ansible_collections/jfrog/platform/roles/postgres/templates/postgres.sh.j2 index ecb4eea2..b6ca1f92 100644 --- a/Ansible/ansible_collections/jfrog/platform/roles/postgres/templates/postgres.sh.j2 +++ b/Ansible/ansible_collections/jfrog/platform/roles/postgres/templates/postgres.sh.j2 @@ -1,4 +1,4 @@ -{{ ansible_managed | comment }} -export PGDATA={{ postgresql_data_dir }} -export LC_ALL={{ postgres_locale }} -export PATH=$PATH:{{ postgresql_bin_path }} +{{ ansible_managed | comment }} +export PGDATA={{ postgresql_data_dir }} +export PATH=$PATH:{{ postgresql_bin_path }} +export LC_ALL={{ postgresql_locale }} diff --git a/Ansible/ansible_collections/jfrog/platform/roles/postgres/templates/postgresql.conf.j2 b/Ansible/ansible_collections/jfrog/platform/roles/postgres/templates/postgresql.conf.j2 deleted file mode 100644 index e34093ee..00000000 --- a/Ansible/ansible_collections/jfrog/platform/roles/postgres/templates/postgresql.conf.j2 +++ /dev/null @@ -1,723 +0,0 @@ -{{ ansible_managed | comment }} -# ----------------------------- -# PostgreSQL configuration file -# ----------------------------- -# -# This file consists of lines of the form: -# -# name = value -# -# (The "=" is optional.) Whitespace may be used. Comments are introduced with -# "#" anywhere on a line. The complete list of parameter names and allowed -# values can be found in the PostgreSQL documentation. -# -# The commented-out settings shown in this file represent the default values. -# Re-commenting a setting is NOT sufficient to revert it to the default value; -# you need to reload the server. -# -# This file is read on server startup and when the server receives a SIGHUP -# signal. If you edit the file on a running system, you have to SIGHUP the -# server for the changes to take effect, run "pg_ctl reload", or execute -# "SELECT pg_reload_conf()". Some parameters, which are marked below, -# require a server shutdown and restart to take effect. -# -# Any parameter can also be given as a command-line option to the server, e.g., -# "postgres -c log_connections=on". Some parameters can be changed at run time -# with the "SET" SQL command. -# -# Memory units: kB = kilobytes Time units: ms = milliseconds -# MB = megabytes s = seconds -# GB = gigabytes min = minutes -# TB = terabytes h = hours -# d = days - - -#------------------------------------------------------------------------------ -# FILE LOCATIONS -#------------------------------------------------------------------------------ - -# The default values of these variables are driven from the -D command-line -# option or PGDATA environment variable, represented here as ConfigDir. - -data_directory = '{{ postgresql_data_dir }}' # use data in another directory - # (change requires restart) -hba_file = '{{ postgresql_config_path }}/pg_hba.conf' # host-based authentication file - # (change requires restart) -ident_file = '{{ postgresql_config_path }}/pg_ident.conf' # ident configuration file - # (change requires restart) - -# If external_pid_file is not explicitly set, no extra PID file is written. -external_pid_file = '{{ postgresql_external_pid_file }}' # write an extra PID file - # (change requires restart) - -#------------------------------------------------------------------------------ -# CONNECTIONS AND AUTHENTICATION -#------------------------------------------------------------------------------ - -# - Connection Settings - - -listen_addresses = '{{ postgres_listen_addresses }}' # what IP address(es) to listen on; - # comma-separated list of addresses; - # defaults to 'localhost'; use '*' for all - # (change requires restart) -port = {{ postgres_port }} # (change requires restart) -max_connections = {{ postgres_server_max_connections }} # (change requires restart) -#superuser_reserved_connections = 3 # (change requires restart) -#unix_socket_directories = '/var/run/postgresql' # comma-separated list of directories - # (change requires restart) -#unix_socket_group = '' # (change requires restart) -#unix_socket_permissions = 0777 # begin with 0 to use octal notation - # (change requires restart) -#bonjour = off # advertise server via Bonjour - # (change requires restart) -#bonjour_name = '' # defaults to the computer name - # (change requires restart) - -# - TCP settings - -# see "man 7 tcp" for details - -#tcp_keepalives_idle = 0 # TCP_KEEPIDLE, in seconds; - # 0 selects the system default -#tcp_keepalives_interval = 0 # TCP_KEEPINTVL, in seconds; - # 0 selects the system default -#tcp_keepalives_count = 0 # TCP_KEEPCNT; - # 0 selects the system default -#tcp_user_timeout = 0 # TCP_USER_TIMEOUT, in milliseconds; - # 0 selects the system default - -# - Authentication - - -#authentication_timeout = 1min # 1s-600s -#ssl = off # (change requires restart) -#ssl_ciphers = 'HIGH:MEDIUM:+3DES:!aNULL' # allowed SSL ciphers - # (change requires restart) -#ssl_prefer_server_ciphers = on # (change requires restart) -#ssl_ecdh_curve = 'prime256v1' # (change requires restart) -#ssl_cert_file = 'server.crt' # (change requires restart) -#ssl_key_file = 'server.key' # (change requires restart) -#ssl_ca_file = '' # (change requires restart) -#ssl_crl_file = '' # (change requires restart) - -{% if _fips_enabled.stdout | default('unknown', true) == '1' %} -password_encryption = scram-sha-256 -{% else %} -#password_encryption = on -{% endif %} -#db_user_namespace = off -#row_security = on - -# GSSAPI using Kerberos -#krb_server_keyfile = '' -#krb_caseins_users = off - - -#------------------------------------------------------------------------------ -# RESOURCE USAGE (except WAL) -#------------------------------------------------------------------------------ - -# - Memory - - -shared_buffers = {{ postgres_server_shared_buffers }} # min 128kB - # (change requires restart) -#huge_pages = try # on, off, or try - # (change requires restart) -#temp_buffers = 8MB # min 800kB -#max_prepared_transactions = 0 # zero disables the feature - # (change requires restart) -# Caution: it is not advisable to set max_prepared_transactions nonzero unless -# you actively intend to use prepared transactions. -#work_mem = 4MB # min 64kB -maintenance_work_mem = {{ postgres_server_maintenance_work_mem }} # min 1MB -#replacement_sort_tuples = 150000 # limits use of replacement selection sort -#autovacuum_work_mem = -1 # min 1MB, or -1 to use maintenance_work_mem -#max_stack_depth = 2MB # min 100kB -dynamic_shared_memory_type = posix # the default is the first option - # supported by the operating system: - # posix - # sysv - # windows - # mmap - # use none to disable dynamic shared memory - # (change requires restart) - -# - Disk - - -#temp_file_limit = -1 # limits per-process temp file space - # in kB, or -1 for no limit - -# - Kernel Resource Usage - - -#max_files_per_process = 1000 # min 25 - # (change requires restart) -shared_preload_libraries = 'pg_stat_statements' # restart on change - -# - Cost-Based Vacuum Delay - - -#vacuum_cost_delay = 0 # 0-100 milliseconds -#vacuum_cost_page_hit = 1 # 0-10000 credits -#vacuum_cost_page_miss = 10 # 0-10000 credits -#vacuum_cost_page_dirty = 20 # 0-10000 credits -#vacuum_cost_limit = 200 # 1-10000 credits - -# - Background Writer - - -#bgwriter_delay = 200ms # 10-10000ms between rounds -#bgwriter_lru_maxpages = 100 # 0-1000 max buffers written/round -#bgwriter_lru_multiplier = 2.0 # 0-10.0 multiplier on buffers scanned/round -#bgwriter_flush_after = 512kB # measured in pages, 0 disables - -# - Asynchronous Behavior - - -effective_io_concurrency = {{ postgres_server_effective_io_concurrency }} -max_worker_processes = {{ postgres_server_max_worker_processes }} -max_parallel_workers_per_gather = {{ postgres_server_max_parallel_maintenance_workers }} -max_parallel_workers_per_gather = {{ postgres_server_max_parallel_workers_per_gather }} -#old_snapshot_threshold = -1 # 1min-60d; -1 disables; 0 is immediate - # (change requires restart) -#backend_flush_after = 0 # measured in pages, 0 disables -{% if postgres_version|string != "9.6" %} -parallel_leader_participation = {{ "on" if postgres_server_parallel_leader_participation else "off" }} -max_parallel_maintenance_workers = {{ postgres_server_max_parallel_maintenance_workers }} -{% endif %} - -#------------------------------------------------------------------------------ -# WRITE AHEAD LOG -#------------------------------------------------------------------------------ - -# - Settings - - -#wal_level = minimal # minimal, replica, or logical - # (change requires restart) -#fsync = on # flush data to disk for crash safety - # (turning this off can cause - # unrecoverable data corruption) -#synchronous_commit = on # synchronization level; - # off, local, remote_write, remote_apply, or on -#wal_sync_method = fsync # the default is the first option - # supported by the operating system: - # open_datasync - # fdatasync (default on Linux) - # fsync - # fsync_writethrough - # open_sync -full_page_writes = {{ "off" if postgres_server_volume_is_zfs else "on" }} # off OK on ZFS # recover from partial page writes - -wal_compression = off # enable compression of full-page writes -#wal_log_hints = off # also do full page writes of non-critical updates - # (change requires restart) -#wal_buffers = -1 # min 32kB, -1 sets based on shared_buffers - # (change requires restart) -#wal_writer_delay = 200ms # 1-10000 milliseconds -#wal_writer_flush_after = 1MB # measured in pages, 0 disables - -commit_delay = 100000 # range 0-100000, in microseconds -#commit_siblings = 5 # range 1-1000 - -# - Checkpoints - - -checkpoint_timeout = 4h # range 30s-1d -max_wal_size = 100GB -min_wal_size = 1GB -checkpoint_completion_target = 0.8 # checkpoint target duration, 0.0 - 1.0 -#checkpoint_flush_after = 256kB # measured in pages, 0 disables -#checkpoint_warning = 30s # 0 disables - -# - Archiving - - -#archive_mode = off # enables archiving; off, on, or always - # (change requires restart) -#archive_command = '' # command to use to archive a logfile segment - # placeholders: %p = path of file to archive - # %f = file name only - # e.g. 'test ! -f /mnt/server/archivedir/%f && cp %p /mnt/server/archivedir/%f' -#archive_timeout = 0 # force a logfile segment switch after this - # number of seconds; 0 disables - -# - Archive Recovery - - -# These are only used in recovery mode. - -#restore_command = '' # command to use to restore an archived logfile segment - # placeholders: %p = path of file to restore - # %f = file name only - # e.g. 'cp /mnt/server/archivedir/%f %p' - # (change requires restart) -#archive_cleanup_command = '' # command to execute at every restartpoint -#recovery_end_command = '' # command to execute at completion of recovery - -# - Recovery Target - - -# Set these only when performing a targeted recovery. - -#recovery_target = '' # 'immediate' to end recovery as soon as a - # consistent state is reached - # (change requires restart) -#recovery_target_name = '' # the named restore point to which recovery will proceed - # (change requires restart) -#recovery_target_time = '' # the time stamp up to which recovery will proceed - # (change requires restart) -#recovery_target_xid = '' # the transaction ID up to which recovery will proceed - # (change requires restart) -#recovery_target_lsn = '' # the WAL LSN up to which recovery will proceed - # (change requires restart) -#recovery_target_inclusive = on # Specifies whether to stop: - # just after the specified recovery target (on) - # just before the recovery target (off) - # (change requires restart) -#recovery_target_timeline = 'latest' # 'current', 'latest', or timeline ID - # (change requires restart) -#recovery_target_action = 'pause' # 'pause', 'promote', 'shutdown' - # (change requires restart) - -#------------------------------------------------------------------------------ -# REPLICATION -#------------------------------------------------------------------------------ - -# - Sending Server(s) - - -# Set these on the master and on any standby that will send replication data. - -#max_wal_senders = 0 # max number of walsender processes - # (change requires restart) -#wal_keep_segments = 0 # in logfile segments, 16MB each; 0 disables -#wal_sender_timeout = 60s # in milliseconds; 0 disables - -#max_replication_slots = 0 # max number of replication slots - # (change requires restart) -#track_commit_timestamp = off # collect timestamp of transaction commit - # (change requires restart) - -# - Master Server - - -# These settings are ignored on a standby server. - -#synchronous_standby_names = '' # standby servers that provide sync rep - # number of sync standbys and comma-separated list of application_name - # from standby(s); '*' = all -#vacuum_defer_cleanup_age = 0 # number of xacts by which cleanup is delayed - -# - Standby Servers - - -# These settings are ignored on a master server. - -#hot_standby = off # "on" allows queries during recovery - # (change requires restart) -#max_standby_archive_delay = 30s # max delay before canceling queries - # when reading WAL from archive; - # -1 allows indefinite delay -#max_standby_streaming_delay = 30s # max delay before canceling queries - # when reading streaming WAL; - # -1 allows indefinite delay -#wal_receiver_status_interval = 10s # send replies at least this often - # 0 disables -#hot_standby_feedback = off # send info from standby to prevent - # query conflicts -#wal_receiver_timeout = 60s # time that receiver waits for - # communication from master - # in milliseconds; 0 disables -#wal_retrieve_retry_interval = 5s # time to wait before retrying to - # retrieve WAL after a failed attempt - -#------------------------------------------------------------------------------ -# QUERY TUNING -#------------------------------------------------------------------------------ - -# - Planner Method Configuration - - -#enable_bitmapscan = on -#enable_hashagg = on -#enable_hashjoin = on -#enable_indexscan = on -#enable_indexonlyscan = on -#enable_material = on -#enable_mergejoin = on -#enable_nestloop = on -#enable_parallel_append = on -#enable_seqscan = on -#enable_sort = on -#enable_tidscan = on -#enable_partitionwise_join = off -#enable_partitionwise_aggregate = off -#enable_parallel_hash = on -#enable_partition_pruning = on - -# - Planner Cost Constants - - -#seq_page_cost = 1.0 # measured on an arbitrary scale -random_page_cost = {{ postgres_server_random_page_cost }} -#cpu_tuple_cost = 0.01 # same scale as above -#cpu_index_tuple_cost = 0.005 # same scale as above -#cpu_operator_cost = 0.0025 # same scale as above -#parallel_tuple_cost = 0.1 # same scale as above -#parallel_setup_cost = 1000.0 # same scale as above - -#jit_above_cost = 100000 # perform JIT compilation if available - # and query more expensive than this; - # -1 disables -#jit_inline_above_cost = 500000 # inline small functions if query is - # more expensive than this; -1 disables -#jit_optimize_above_cost = 500000 # use expensive JIT optimizations if - # query is more expensive than this; - # -1 disables - -#min_parallel_table_scan_size = 8MB -#min_parallel_index_scan_size = 512kB -#effective_cache_size = 4GB - -# - Genetic Query Optimizer - - -#geqo = on -#geqo_threshold = 12 -#geqo_effort = 5 # range 1-10 -#geqo_pool_size = 0 # selects default based on effort -#geqo_generations = 0 # selects default based on effort -#geqo_selection_bias = 2.0 # range 1.5-2.0 -#geqo_seed = 0.0 # range 0.0-1.0 - -# - Other Planner Options - - -#default_statistics_target = 100 # range 1-10000 -#constraint_exclusion = partition # on, off, or partition -#cursor_tuple_fraction = 0.1 # range 0.0-1.0 -#from_collapse_limit = 8 -#join_collapse_limit = 8 # 1 disables collapsing of explicit - # JOIN clauses -#force_parallel_mode = off -#jit = on # allow JIT compilation -#plan_cache_mode = auto # auto, force_generic_plan or - # force_custom_plan - - -#------------------------------------------------------------------------------ -# ERROR REPORTING AND LOGGING -#------------------------------------------------------------------------------ - -# - Where to Log - - -log_destination = 'stderr' # Valid values are combinations of - # stderr, csvlog, syslog, and eventlog, - # depending on platform. csvlog - # requires logging_collector to be on. - -# This is used when logging to stderr: -logging_collector = on # Enable capturing of stderr and csvlog - # into log files. Required to be on for - # csvlogs. - # (change requires restart) - -# These are only used if logging_collector is on: -log_directory = 'pg_log' # directory where log files are written, - # can be absolute or relative to PGDATA -log_filename = 'postgresql-%a.log' # log file name pattern, - # can include strftime() escapes -#log_file_mode = 0600 # creation mode for log files, - # begin with 0 to use octal notation -log_truncate_on_rotation = on # If on, an existing log file with the - # same name as the new log file will be - # truncated rather than appended to. - # But such truncation only occurs on - # time-driven rotation, not on restarts - # or size-driven rotation. Default is - # off, meaning append to existing files - # in all cases. -log_rotation_age = 1d # Automatic rotation of logfiles will - # happen after that time. 0 disables. -log_rotation_size = 0 # Automatic rotation of logfiles will - # happen after that much log output. - # 0 disables. - -# These are relevant when logging to syslog: -#syslog_facility = 'LOCAL0' -#syslog_ident = 'postgres' -#syslog_sequence_numbers = on -#syslog_split_messages = on - -# This is only relevant when logging to eventlog (win32): -# (change requires restart) -#event_source = 'PostgreSQL' - -# - When to Log - - -#client_min_messages = notice # values in order of decreasing detail: - # debug5 - # debug4 - # debug3 - # debug2 - # debug1 - # log - # notice - # warning - # error - -#log_min_messages = warning # values in order of decreasing detail: - # debug5 - # debug4 - # debug3 - # debug2 - # debug1 - # info - # notice - # warning - # error - # log - # fatal - # panic - -#log_min_error_statement = error # values in order of decreasing detail: - # debug5 - # debug4 - # debug3 - # debug2 - # debug1 - # info - # notice - # warning - # error - # log - # fatal - # panic (effectively off) - -#log_min_duration_statement = -1 # -1 is disabled, 0 logs all statements - # and their durations, > 0 logs only - # statements running at least this number - # of milliseconds - - -# - What to Log - - -#debug_print_parse = off -#debug_print_rewritten = off -#debug_print_plan = off -#debug_pretty_print = on -log_checkpoints = {{ "on" if postgres_server_log_checkpoints else "off" }} -log_connections = {{ "on" if postgres_server_log_connections else "off" }} -log_disconnections = {{ "on" if postgres_server_log_disconnections else "off" }} -log_duration = {{ "on" if postgres_server_log_duration else "off" }} -log_error_verbosity = {{ postgres_server_log_error_verbosity }} # terse, default, or verbose messages -log_hostname = {{ "on" if postgres_server_log_hostname else "off" }} -log_line_prefix = '< %m > ' # special values: - # %a = application name - # %u = user name - # %d = database name - # %r = remote host and port - # %h = remote host - # %p = process ID - # %t = timestamp without milliseconds - # %m = timestamp with milliseconds - # %n = timestamp with milliseconds (as a Unix epoch) - # %i = command tag - # %e = SQL state - # %c = session ID - # %l = session line number - # %s = session start timestamp - # %v = virtual transaction ID - # %x = transaction ID (0 if none) - # %q = stop here in non-session - # processes - # %% = '%' - # e.g. '<%u%%%d> ' -log_lock_waits = {{ "on" if postgres_server_log_lock_waits else "off" }} # log lock waits >= deadlock_timeout -log_statement = '{{ postgres_server_log_statements }}' # none, ddl, mod, all -#log_replication_commands = off -#log_temp_files = -1 # log temporary files equal or larger - # than the specified size in kilobytes; - # -1 disables, 0 logs all temp files -log_timezone = 'Etc/UTC' - - -# - Process Title - - -#cluster_name = '' # added to process titles if nonempty - # (change requires restart) -#update_process_title = on - - -#------------------------------------------------------------------------------ -# RUNTIME STATISTICS -#------------------------------------------------------------------------------ - -# - Query/Index Statistics Collector - - -#track_activities = on -#track_counts = on -#track_io_timing = off -#track_functions = none # none, pl, all -track_activity_query_size = 102400 # (change requires restart) -#stats_temp_directory = 'pg_stat_tmp' - -# Track statements generated by stored procedures as well -pg_stat_statements.track = all - - -# - Statistics Monitoring - - -#log_parser_stats = off -#log_planner_stats = off -#log_executor_stats = off -#log_statement_stats = off - - -#------------------------------------------------------------------------------ -# AUTOVACUUM PARAMETERS -#------------------------------------------------------------------------------ - -#autovacuum = on # Enable autovacuum subprocess? 'on' - # requires track_counts to also be on. -#log_autovacuum_min_duration = -1 # -1 disables, 0 logs all actions and - # their durations, > 0 logs only - # actions running at least this number - # of milliseconds. -#autovacuum_max_workers = 3 # max number of autovacuum subprocesses - # (change requires restart) -#autovacuum_naptime = 1min # time between autovacuum runs -#autovacuum_vacuum_threshold = 50 # min number of row updates before - # vacuum -#autovacuum_analyze_threshold = 50 # min number of row updates before - # analyze -#autovacuum_vacuum_scale_factor = 0.2 # fraction of table size before vacuum -#autovacuum_analyze_scale_factor = 0.1 # fraction of table size before analyze -#autovacuum_freeze_max_age = 200000000 # maximum XID age before forced vacuum - # (change requires restart) -#autovacuum_multixact_freeze_max_age = 400000000 # maximum multixact age - # before forced vacuum - # (change requires restart) -#autovacuum_vacuum_cost_delay = 20ms # default vacuum cost delay for - # autovacuum, in milliseconds; - # -1 means use vacuum_cost_delay -#autovacuum_vacuum_cost_limit = -1 # default vacuum cost limit for - # autovacuum, -1 means use - # vacuum_cost_limit - - -#------------------------------------------------------------------------------ -# CLIENT CONNECTION DEFAULTS -#------------------------------------------------------------------------------ - -# - Statement Behavior - - -#search_path = '"$user", public' # schema names -#default_tablespace = '' # a tablespace name, '' uses the default -#temp_tablespaces = '' # a list of tablespace names, '' uses - # only default tablespace -#check_function_bodies = on -#default_transaction_isolation = 'read committed' -#default_transaction_read_only = off -#default_transaction_deferrable = off -#session_replication_role = 'origin' -#statement_timeout = 0 # in milliseconds, 0 is disabled -#lock_timeout = 0 # in milliseconds, 0 is disabled -#idle_in_transaction_session_timeout = 0 # in milliseconds, 0 is disabled -#vacuum_freeze_min_age = 50000000 -#vacuum_freeze_table_age = 150000000 -#vacuum_multixact_freeze_min_age = 5000000 -#vacuum_multixact_freeze_table_age = 150000000 -#bytea_output = 'hex' # hex, escape -#xmlbinary = 'base64' -#xmloption = 'content' -#gin_fuzzy_search_limit = 0 -#gin_pending_list_limit = 4MB - -# - Locale and Formatting - - -datestyle = 'iso, mdy' -#intervalstyle = 'postgres' -timezone = 'Europe/Berlin' -#timezone_abbreviations = 'Default' # Select the set of available time zone - # abbreviations. Currently, there are - # Default - # Australia (historical usage) - # India - # You can create your own file in - # share/timezonesets/. -#extra_float_digits = 0 # min -15, max 3 -#client_encoding = sql_ascii # actually, defaults to database - # encoding - -# These settings are initialized by initdb, but they can be changed. -lc_messages = 'en_US.UTF-8' # locale for system error message - # strings -lc_monetary = 'en_US.UTF-8' # locale for monetary formatting -lc_numeric = 'en_US.UTF-8' # locale for number formatting -lc_time = 'en_US.UTF-8' # locale for time formatting - -# default configuration for text search -default_text_search_config = 'pg_catalog.english' - -# - Other Defaults - - -#dynamic_library_path = '$libdir' -#local_preload_libraries = '' -{% set preload_libraries = [] %} -{% if postgres_server_auto_explain_enabled %} - {{ preload_libraries.append("auto_explain") }} -{% endif %} - -session_preload_libraries = '{{ ",".join(preload_libraries) }}' - -#------------------------------------------------------------------------------ -# auto_explain SETTINGS -#------------------------------------------------------------------------------ - -auto_explain.log_min_duration = {{ "on" if postgres_server_auto_explain_log_min_duration else "off" }} -auto_explain.log_analyze = {{ "on" if postgres_server_auto_explain_log_analyze else "off" }} - -#------------------------------------------------------------------------------ -# LOCK MANAGEMENT -#------------------------------------------------------------------------------ - -#deadlock_timeout = 1s -max_locks_per_transaction = {{ postgres_server_max_locks_per_transaction }} # min 10 - # (change requires restart) -#max_pred_locks_per_transaction = 64 # min 10 - # (change requires restart) - - -#------------------------------------------------------------------------------ -# VERSION/PLATFORM COMPATIBILITY -#------------------------------------------------------------------------------ - -# - Previous PostgreSQL Versions - - -#array_nulls = on -#backslash_quote = safe_encoding # on, off, or safe_encoding -#default_with_oids = off -#escape_string_warning = on -#lo_compat_privileges = off -#operator_precedence_warning = off -#quote_all_identifiers = off -#sql_inheritance = on -#standard_conforming_strings = on -#synchronize_seqscans = on - -# - Other Platforms and Clients - - -#transform_null_equals = off - - -#------------------------------------------------------------------------------ -# ERROR HANDLING -#------------------------------------------------------------------------------ - -#exit_on_error = off # terminate session on any error? -#restart_after_crash = on # reinitialize after backend crash? - - -#------------------------------------------------------------------------------ -# CONFIG FILE INCLUDES -#------------------------------------------------------------------------------ - -# These options allow settings to be loaded from files other than the -# default postgresql.conf. - -#include_dir = 'conf.d' # include files ending in '.conf' from - # directory 'conf.d' -#include_if_exists = 'exists.conf' # include file only if it exists -#include = 'special.conf' # include file - - -#------------------------------------------------------------------------------ -# CUSTOMIZED OPTIONS -#------------------------------------------------------------------------------ - -# Add settings for extensions here - diff --git a/Ansible/ansible_collections/jfrog/platform/roles/postgres/vars/Debian.yml b/Ansible/ansible_collections/jfrog/platform/roles/postgres/vars/Debian.yml deleted file mode 100644 index ee4d18d3..00000000 --- a/Ansible/ansible_collections/jfrog/platform/roles/postgres/vars/Debian.yml +++ /dev/null @@ -1,14 +0,0 @@ -default_postgresql_bin_path: /usr/lib/postgresql/{{ postgres_version }}/bin -default_postgresql_config_path: /etc/postgresql/{{ postgres_version }}/main -default_postgresql_data_dir: /var/lib/postgresql/{{ postgres_version }}/main -default_postgresql_daemon: postgresql@{{ postgres_version }}-main -default_postgresql_external_pid_file: /var/run/postgresql/{{ postgres_version }}-main.pid - -default_postgres_apt_key_id: '0x7FCC7D46ACCC4CF8' -default_postgres_apt_key_url: https://www.postgresql.org/media/keys/ACCC4CF8.asc -default_postgres_apt_repository_repo: >- - {%- if ansible_distribution_release == 'bionic' -%} - deb https://apt-archive.postgresql.org/pub/repos/apt {{ ansible_distribution_release }}-pgdg main - {%- else -%} - deb https://apt.postgresql.org/pub/repos/apt/ {{ ansible_distribution_release }}-pgdg main - {%- endif -%} \ No newline at end of file diff --git a/Ansible/ansible_collections/jfrog/platform/roles/postgres/vars/RedHat.yml b/Ansible/ansible_collections/jfrog/platform/roles/postgres/vars/RedHat.yml deleted file mode 100644 index fa7a7cba..00000000 --- a/Ansible/ansible_collections/jfrog/platform/roles/postgres/vars/RedHat.yml +++ /dev/null @@ -1,5 +0,0 @@ -default_postgresql_bin_path: /usr/pgsql-{{ postgres_version }}/bin -default_postgresql_config_path: /var/lib/pgsql/{{ postgres_version }}/data -default_postgresql_data_dir: /var/lib/pgsql/{{ postgres_version }}/data -default_postgresql_daemon: postgresql-{{ postgres_version }}.service -default_postgresql_external_pid_file: /var/run/postgresql/{{ postgres_version }}-main.pid diff --git a/Ansible/ansible_collections/jfrog/platform/roles/postgres/vars/all.yml b/Ansible/ansible_collections/jfrog/platform/roles/postgres/vars/all.yml new file mode 100644 index 00000000..f05fb167 --- /dev/null +++ b/Ansible/ansible_collections/jfrog/platform/roles/postgres/vars/all.yml @@ -0,0 +1,5 @@ +--- +# Our mapping to find out if PostgreSQL is supported or not +distribution_postgresql_support_map: + redhat8: [10, 12, 13, 15, 16] + redhat9: [13, 15, 16] diff --git a/Ansible/ansible_collections/jfrog/platform/roles/postgres/vars/debian.yml b/Ansible/ansible_collections/jfrog/platform/roles/postgres/vars/debian.yml new file mode 100644 index 00000000..e9c83574 --- /dev/null +++ b/Ansible/ansible_collections/jfrog/platform/roles/postgres/vars/debian.yml @@ -0,0 +1,32 @@ +--- +postgresql_bin_path: "/usr/lib/postgresql/{{ postgresql_version }}/bin" +postgresql_data_dir: "/var/lib/postgresql/{{ postgresql_version }}/main" +postgresql_config_dir: "/etc/postgresql/{{ postgresql_version }}/main" +postgresql_config_file: "/etc/postgresql/{{ postgresql_version }}/main/postgresql.conf" +postgresql_daemon: "{{ 'postgresql@' ~ postgresql_version ~ '-main' if postgresql_use_official_repos else 'postgresql' }}" + +postgresql_unix_socket_directories_mode: '0755' +postgresql_unix_socket_directories: + - /var/run/postgresql + +postgresql_external_pid_file: "{{ '/var/run/postgresql/' ~ postgres_version '-main.pid' }}" + +# System logrotation drop-in directory +logrotate_dir: '/etc/logrotate.d' + +# PostgreSQL Repository variables +postgresql_repo_key_id: '0x7FCC7D46ACCC4CF8' +postgresql_repo_key_url: 'https://www.postgresql.org/media/keys/ACCC4CF8.asc' +postgresql_repo_url: "deb https://apt.postgresql.org/pub/repos/apt/ {{ ansible_facts['distribution_release'] | lower }}-pgdg main" + +# PostgreSQL Server Packages +postgresql_packages: >- + {{ + ['postgresql-' ~ postgresql_version ~ '-server', 'postgresql-contrib-' ~ postgresql_version] + if artifactory_postgresql_use_official_repos + else + ['postgresql', 'postgresql-contrib', 'libpq-dev'] + }} + +# PostgreSQL Python Library Package +postgresql_python_library: 'python3-psycopg2' diff --git a/Ansible/ansible_collections/jfrog/platform/roles/postgres/vars/redhat.yml b/Ansible/ansible_collections/jfrog/platform/roles/postgres/vars/redhat.yml new file mode 100644 index 00000000..7955f046 --- /dev/null +++ b/Ansible/ansible_collections/jfrog/platform/roles/postgres/vars/redhat.yml @@ -0,0 +1,68 @@ +--- +postgresql_bin_path: >- + "{{ '/usr/pgsql-' ~ postgresql_version ~ '/bin' + if postgresql_use_official_repos else '/usr/bin' }}" + +postgresql_data_dir: >- + "{{ '/var/lib/pgsql/' ~ postgresql_version ~ '/data' + if postgresql_use_official_repos else '/var/lib/pgsql/data' }}" + +postgresql_config_dir: >- + "{{ '/var/lib/pgsql/' ~ postgresql_version ~ '/data' + if postgresql_use_official_repos else '/var/lib/pgsql/data' }}" + +postgresql_config_file: >- + "{{ '/var/lib/pgsql/' ~ postgresql_version ~ '/data/postgresql.conf' + if postgresql_use_official_repos else '/var/lib/pgsql/data/postgresql.conf' }}" + +postgresql_daemon: >- + "{{ 'postgresql-' ~ postgresql_version ~ '.service' + if postgresql_use_official_repos else 'postgresql' }}" + +postgresql_unix_socket_directories_mode: '0755' +postgresql_unix_socket_directories: + - /var/run/postgresql + +postgresql_external_pid_file: "{{ '/var/run/postgresql/' ~ postgres_version '-main.pid' }}" + +# System logrotation drop-in directory +logrotate_dir: '/etc/logrotate.d' + +# PostgreSQL Repository variables +postgresql_repo_key_id: '' +postgresql_repo_key_url: >- + {{ + 'https://download.postgresql.org/pub/repos/yum/keys/PGDG-RPM-GPG-KEY-Fedora' + if ansible_facts['distribution'] | lower == 'fedora' + else + 'https://download.postgresql.org/pub/repos/yum/keys/PGDG-RPM-GPG-KEY-AARCH64-RHEL' + if ansible_facts['architecture'] | lower == 'aarch64' + else + 'https://download.postgresql.org/pub/repos/yum/keys/PGDG-RPM-GPG-KEY-RHEL' + }} + +postgresql_repo_url: >- + {{ + 'https://download.postgresql.org/pub/repos/yum/reporpms/EL-' + ~ ansible_facts['distribution_major_version'] + ~ '-' + ~ ansible_facts['architecture'] | lower + ~ '/pgdg-' + ~ ansible_facts['distribution'] | lower + ~ '-repo-latest.noarch.rpm' + }} + +# PostgreSQL Server Packages +postgresql_packages: >- + {{ + ['postgresql' ~ postgresql_version ~ '-server', 'postgresql' ~ postgresql_version ~ '-contrib'] + if artifactory_postgresql_use_official_repos + else + (['@postgresql:' ~ postgresql_version ~ '/server', 'postgresql-contrib'] + if postgresql_version != '13' + else + ['postgresql-server', 'postgresql-contrib']) + }} + +# PostgreSQL Python Library Package +postgresql_python_library: 'python3-psycopg2'