diff --git a/README.md b/README.md index 15dc334..6052682 100644 --- a/README.md +++ b/README.md @@ -1 +1,7 @@ -Setup pgbouncer for RHEL8 +Setup pgbouncer + +Tested with OS: + - AlmaLinux 8/9 + - Debian 11 + - Ubuntu 20.04/22.04 + diff --git a/defaults/main.yaml b/defaults/main.yaml index d7b9a4d..7fcbfd3 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -1,3 +1,4 @@ +pgbouncer_postgresql_major_version: "15" pgbouncer_conf_dir: "/etc/pgbouncer" pgbouncer_conf_name: "pgbouncer.ini" pgbouncer_log_dir: "/var/log/pgbouncer" @@ -14,7 +15,7 @@ pgbouncer_default_pool_mode: "session" pgbouncer_ignore_startup_parameters: "extra_float_digits,geqo" pgbouncer_auth_type: "hba" pgbouncer_auth_user: "postgres" -pgbouncer_auth_hba_file: "{{ pgbouncer_postgresql_home_dir }}/{{ pgbouncer_postgresql_major_version }}/data/pg_hba.conf" +pgbouncer_auth_hba_file: "{{ pgbouncer_postgresql_config_cluster_dir }}/pg_hba.conf" pgbouncer_auth_file_name: "userlist.txt" pgbouncer_auth_file: "{{ pgbouncer_conf_dir }}/{{ pgbouncer_auth_file_name }}" pgbouncer_admin_users: "postgres" diff --git a/handlers/main.yaml b/handlers/main.yaml index 12358ae..a900798 100644 --- a/handlers/main.yaml +++ b/handlers/main.yaml @@ -1,5 +1,4 @@ --- - - name: Restart pgbouncer service systemd: daemon_reload: true @@ -18,5 +17,3 @@ delay: 5 ignore_errors: false listen: "restart pgbouncer" - -... diff --git a/tasks/main.yaml b/tasks/main.yaml index 1d92ac2..995e76c 100644 --- a/tasks/main.yaml +++ b/tasks/main.yaml @@ -1,50 +1,48 @@ --- -# yamllint disable rule:line-length - - name: Make sure handlers are flushed immediately meta: flush_handlers +- name: Gather packages + package_facts: + manager: auto + - name: Load a variable file based on the OS type include_vars: "{{ lookup('first_found', params) }}" vars: params: files: + - "{{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_major_version'] }}.yaml" + - "{{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_version'] }}.yaml" + - "{{ ansible_facts['os_family'] }}-{{ ansible_facts['distribution_major_version'] }}.yaml" + - "{{ ansible_facts['os_family'] }}-{{ ansible_facts['distribution_version'] }}.yaml" - "{{ ansible_facts['distribution'] }}.yaml" - "{{ ansible_facts['os_family'] }}.yaml" paths: - "vars" tags: pgbouncer_vars -- name: "Gather packages" - package_facts: - manager: auto - - name: "Set fact about PostgreSQL package" set_fact: pgbouncer_postgresql_package_name: "{{ ansible_facts.packages | list | select('match', pgbouncer_postgresql_package_name_regex) | first }}" -- name: "Get PostgreSQL major and minor versions" +- name: "Get PostgreSQL major version" set_fact: pgbouncer_postgresql_major_version: "{{ ansible_facts.packages[pgbouncer_postgresql_package_name][0]['version'] | split('.') | first }}" pgbouncer_postgresql_minor_version: "{{ ansible_facts.packages[pgbouncer_postgresql_package_name][0]['version'] | split('.') | last }}" +- name: Mask pgbouncer before install + systemd: + name: pgbouncer + masked: yes + when: + - ansible_os_family == "Debian" + - "'pgbouncer' not in ansible_facts.packages" + tags: pgbouncer_mask, pgbouncer + - name: Install pgbouncer package package: name: pgbouncer environment: "{{ proxy_env | default({}) }}" - when: ansible_os_family == "Debian" or - (ansible_os_family == "RedHat" and - ansible_distribution_major_version == '7') - tags: pgbouncer_install, pgbouncer - -# RHEL 8 -- name: Install pgbouncer package - dnf: - name: pgbouncer - disablerepo: AppStream - environment: "{{ proxy_env | default({}) }}" - when: ansible_os_family == "RedHat" and - ansible_distribution_major_version >= '8' tags: pgbouncer_install, pgbouncer - name: Ensure config directory "{{ pgbouncer_conf_dir }}" exist @@ -56,14 +54,6 @@ mode: 0750 tags: pgbouncer_conf, pgbouncer -- name: Stop and disable standard init script - service: - name: pgbouncer - state: stopped - enabled: false - when: ansible_os_family == "Debian" - tags: pgbouncer_service, pgbouncer - - name: Add pgbouncer systemd unit user and group override block: - name: Ensure override dir for pgbouncer exists @@ -159,3 +149,4 @@ masked: no register: pgbouncer_enable_and_start tags: pgbouncer, pgbouncer_start + diff --git a/vars/Debian.yaml b/vars/Debian.yaml index 1e76d07..a73cf0c 100644 --- a/vars/Debian.yaml +++ b/vars/Debian.yaml @@ -1,2 +1,8 @@ +pgbouncer_postgresql_config_dir: "/etc/postgresql" +pgbouncer_postgresql_config_cluster_dir: "{{ pgbouncer_postgresql_config_dir }}/{{ pgbouncer_postgresql_major_version }}/{{ pgbouncer_postgresql_cluster_name }}" pgbouncer_postgresql_home_dir: "/var/lib/postgresql" +pgbouncer_postgresql_data_dir: "{{ pgbouncer_postgresql_home_dir }}/{{ pgbouncer_postgresql_major_version }}/{{ pgbouncer_postgresql_cluster_name }}" +pgbouncer_postgresql_ssl_path: "{{ pgbouncer_postgresql_config_dir }}/{{ pgbouncer_postgresql_major_version }}/{{ pgbouncer_postgresql_cluster_name }}" +pgbouncer_postgresql_cluster_name: "main" + pgbouncer_postgresql_package_name_regex: 'postgresql-.[{{ pgbouncer_postgresql_supported_versions | join(",") }}]' diff --git a/vars/RedHat.yaml b/vars/RedHat.yaml index b6aea46..51bd25c 100644 --- a/vars/RedHat.yaml +++ b/vars/RedHat.yaml @@ -1,2 +1,7 @@ pgbouncer_postgresql_home_dir: "/var/lib/pgsql" +pgbouncer_postgresql_data_dir: "{{ pgbouncer_postgresql_home_dir }}/{{ pgbouncer_postgresql_major_version }}/data" +pgbouncer_postgresql_ssl_path: "{{ pgbouncer_postgresql_home_dir }}/{{ pgbouncer_postgresql_major_version }}" +pgbouncer_postgresql_config_dir: "{{ pgbouncer_postgresql_data_dir }}" +pgbouncer_postgresql_config_cluster_dir: "{{ pgbouncer_postgresql_data_dir }}" + pgbouncer_postgresql_package_name_regex: 'postgresql.[{{ pgbouncer_postgresql_supported_versions | join(",") }}]-server' diff --git a/vars/main.yaml b/vars/main.yaml new file mode 100644 index 0000000..8fe1be9 --- /dev/null +++ b/vars/main.yaml @@ -0,0 +1,5 @@ +postgresql_major_version: "{{ postgresql_version | split('.') | first }}" +postgresql_minor_version: "{{ postgresql_version | split('.') | last }}" +postgresql_system_locale: "en_US.UTF-8" +postgresql_system_language: "{{ postgresql_system_locale }}" +postgresql_system_override_dir: "/etc/systemd/system/postgresql-{{ postgresql_major_version }}.service.d"