split variables for RedHat and Debain os family

This commit is contained in:
ace 2023-04-16 03:31:57 +03:00
parent 7940184553
commit 9668298b45
Signed by: ace
GPG Key ID: 2C08973DD37A76FD
7 changed files with 44 additions and 33 deletions

View File

@ -1 +1,7 @@
Setup pgbouncer for RHEL8
Setup pgbouncer
Tested with OS:
- AlmaLinux 8/9
- Debian 11
- Ubuntu 20.04/22.04

View File

@ -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"

View File

@ -1,5 +1,4 @@
---
- name: Restart pgbouncer service
systemd:
daemon_reload: true
@ -18,5 +17,3 @@
delay: 5
ignore_errors: false
listen: "restart pgbouncer"
...

View File

@ -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

View File

@ -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(",") }}]'

View File

@ -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'

5
vars/main.yaml Normal file
View File

@ -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"