add Debian os family support

This commit is contained in:
ace 2023-03-29 23:49:37 +03:00
parent 30ba577f3a
commit b443059313
Signed by: ace
GPG Key ID: 2C08973DD37A76FD
24 changed files with 463 additions and 308 deletions

View File

@ -1,4 +1,10 @@
Setup Patroni cluster for RHEL8 Setup Patroni cluster
Tested with OS:
- AlmaLinux 8/9
- Debian 11
- Ubuntu 20.04/22.04
Supported PostgreSQL versions: Supported PostgreSQL versions:
- 13 - 13
- 14 - 14

View File

@ -1,6 +1,6 @@
# Patroni common options # Patroni common options
patroni_version: "3.0.0" patroni_version: "3.0.1"
patroni_install_repo: true patroni_install_official_repo: true
# Patroni cluster options # Patroni cluster options
patroni_cluster_name: "patroni-cluster" patroni_cluster_name: "patroni-cluster"
@ -9,6 +9,8 @@ patroni_namespace: "/service/"
# Patroni PostgreSQL common options # Patroni PostgreSQL common options
patroni_postgresql_version: "15.2" patroni_postgresql_version: "15.2"
patroni_postgresql_install_repo: true patroni_postgresql_install_repo: true
patroni_postgresql_system_locale: "en_US.UTF-8"
patroni_postgresql_system_language: "{{ patroni_postgresql_system_locale }}"
# Patroni superuser auth # Patroni superuser auth
patroni_superuser_username: "postgres" patroni_superuser_username: "postgres"
@ -28,6 +30,7 @@ patroni_ssl: false
patroni_ssl_path: "/etc/patroni/ssl" patroni_ssl_path: "/etc/patroni/ssl"
patroni_self_signed_cert: false patroni_self_signed_cert: false
patroni_self_signed_cert_name: "cert" patroni_self_signed_cert_name: "cert"
patroni_play_group: "patroni"
## DCS options. Consul or Etcd ## DCS options. Consul or Etcd
patroni_dcs_exists: false patroni_dcs_exists: false
@ -35,3 +38,4 @@ patroni_dcs_type: "consul"
## Backup options ## Backup options
patroni_wal_g_install: false patroni_wal_g_install: false

View File

@ -1,69 +1,3 @@
- name: Add gpg package - name: "Install Patroni {{ patroni_version }}"
apt: include_tasks: patroni_install.yaml
name: gpg tags: patroni_install
- name: Add gpg keys for patroni
ansible.builtin.apt_key:
url: "{{ item.url }}"
keyring: "{{ item.keyring }}"
loop: "{{ patroni_apt_key }}"
- name: Add Patroni repository
apt_repository:
repo: "{{ item.repo }}"
state: present
filename: "{{ item.filename }}"
update_cache: yes
loop: "{{ patroni_apt_repository }}"
- name: Check if PostgreSQL is installed
ansible.builtin.shell: dpkg-query -l {{ patroni_postgresql_package_name }} 2>&1 | grep {{ patroni_postgresql_version }}
ignore_errors: True
register: is_patroni_postgresql
changed_when: is_patroni_postgresql.rc != 0
failed_when: False
- name: Mask PostgreSQL before install
ansible.builtin.systemd:
name: "{{ patroni_postgresql_package_name }}"
masked: yes
when: is_patroni_postgresql.rc != 0
- name: "Install {{ patroni_postgresql_package_name }}-{{ patroni_postgresql_version }}"
apt:
name: "{{ patroni_postgresql_package }}"
update_cache: yes
register: patroni_postgresql_setup
when: is_patroni_postgresql.rc != 0
- name: Unmask PostgreSQL after install
ansible.builtin.systemd:
name: "{{ patroni_postgresql_package_name }}"
masked: no
when: is_patroni_postgresql.rc != 0
- name: Check if Patroni is installed
ansible.builtin.shell: dpkg-query -l {{ patroni_package_name }} 2>&1 | grep {{ patroni_version }}
ignore_errors: True
register: is_patroni
changed_when: is_patroni.rc != 0
failed_when: False
- name: Mask Patroni before install
ansible.builtin.systemd:
name: "{{ patroni_package_name }}"
masked: yes
when: is_patroni.rc != 0
- name: "Install {{ patroni_package_name }}-{{ patroni_version }}"
apt:
name: "{{ patroni_package }}"
update_cache: yes
register: patroni_setup
when: is_patroni.rc != 0
- name: Unmask Patroni after install
ansible.builtin.systemd:
name: "{{ patroni_package_name }}"
masked: no
when: is_patroni.rc != 0

View File

@ -0,0 +1,37 @@
- name: Gather packages
package_facts:
manager: auto
- name: Set fact about Patroni package
set_fact:
patroni_installed_package: "{{ ansible_facts.packages[patroni_package_name][0]['name'] }}"
when: patroni_package_name in ansible_facts.packages
- name: Print installed Patroni version
debug:
msg: "{{ ansible_facts.packages[patroni_package_name][0]['version'] }}"
verbosity: 2
when: patroni_installed_package is defined
- name: Mask Patroni before install
ansible.builtin.systemd:
name: "{{ patroni_unit_name }}"
masked: yes
when: patroni_package_name not in ansible_facts.packages or ansible_facts.packages[patroni_package_name][0]['version'] != (patroni_version|string + "-" + patroni_version_build|string)
- name: "Install {{ patroni_package_name }}-{{ patroni_version }}-{{ patroni_version_build }}"
apt:
name: "{{ patroni_package }}"
update_cache: yes
register: patroni_setup
when: patroni_package_name not in ansible_facts.packages
- name: "Update {{ patroni_package_name }}-{{ patroni_version }}-{{ patroni_version_build }}"
apt:
name: "{{ patroni_package }}"
update_cache: yes
register: patroni_update
notify: Restart Patroni
when:
- patroni_package_name in ansible_facts.packages
- ansible_facts.packages[patroni_package_name][0]['version'] != (patroni_version|string + "-" + patroni_version_build|string)

View File

@ -0,0 +1,20 @@
- name: Install deps packages
apt:
name: "{{ patroni_deps_packages }}"
state: present
update_cache: yes
- name: Add gpg keys for patroni
ansible.builtin.apt_key:
url: "{{ item.url }}"
keyring: "{{ item.keyring }}"
loop: "{{ patroni_apt_key }}"
- name: Add Patroni repository
apt_repository:
repo: "{{ item.repo }}"
state: present
filename: "{{ item.filename }}"
update_cache: yes
loop: "{{ patroni_apt_repository }}"

View File

@ -0,0 +1,52 @@
- name: Install postgresql-common
apt:
name: postgresql-common
state: present
- name: Create dir createcluster.d
file:
path: /etc/postgresql-common/createcluster.d
state: directory
- name: Disable main cluster creation by default
copy:
dest: /etc/postgresql-common/createcluster.d/create-main-cluster.conf
content: |
create_main_cluster = false
- name: Gather packages
package_facts:
manager: auto
- name: Set fact about PostgreSQL package
set_fact:
patroni_postgresql_installed_package: "{{ ansible_facts.packages[patroni_postgresql_package_name][0]['name'] }}"
when: patroni_postgresql_package_name in ansible_facts.packages
- name: Print installed PostgreSQL version
debug:
msg: "{{ ansible_facts.packages[patroni_postgresql_package_name][0]['version'] }}"
verbosity: 2
when: patroni_postgresql_installed_package is defined
- name: Mask PostgreSQL before install
ansible.builtin.systemd:
name: "{{ patroni_postgresql_unit_name }}"
masked: yes
when: patroni_postgresql_package_name not in ansible_facts.packages or ansible_facts.packages[patroni_postgresql_package_name][0]['version'] != (patroni_postgresql_version|string + "-" + patroni_postgresql_version_build|string)
- name: "Install {{ patroni_postgresql_package_name }}-{{ patroni_postgresql_version }}-{{ patroni_postgresql_version_build }}"
apt:
name: "{{ patroni_postgresql_package }}"
update_cache: yes
register: patroni_postgresql_setup
when: patroni_postgresql_package_name not in ansible_facts.packages
- name: "Update {{ patroni_postgresql_package_name }}-{{ patroni_postgresql_version }}-{{ patroni_postgresql_version_build }}"
apt:
name: "{{ patroni_postgresql_package }}"
update_cache: yes
register: patroni_postgresql_update
when:
- patroni_postgresql_package_name in ansible_facts.packages
- ansible_facts.packages[patroni_postgresql_package_name][0]['version'] != (patroni_postgresql_version|string + "-" + patroni_postgresql_version_build|string)

View File

@ -1,45 +0,0 @@
- name: Install Patroni {{ patroni_version }} with Python 3.6
when: "patroni_use_python39 is not defined or not patroni_use_python39"
block:
- name: Add Patroni repository
dnf:
name: "{{ patroni_repo_package }}"
state: present
disable_gpg_check: yes
- name: "Install Patroni {{ patroni_version }} with Python 3.6"
dnf:
name: "{{ item }}"
state: present
disable_gpg_check: yes
update_cache: yes
loop:
- "{{ patroni_default_packages }}"
register: patroni_setup
- name: Install Patroni {{ patroni_version }} with Python 3.9
when:
- patroni_use_python39 is defined
- patroni_use_python39
block:
- name: Enable Python 3.9 module
shell: dnf module enable -y python39
register: enable_python39_module
changed_when: "'Nothing to do' not in enable_python39_module.stdout"
- name: Install Python 3.9
dnf:
name: python39
state: present
- name: Set python3.9 as python
shell: alternatives --set python /usr/bin/python3.9
register: set_python39_as_python
changed_when: false
failed_when: set_python39_as_python.stdout != ''
- name: "Install Patroni {{ patroni_version }} with Python 3.9"
dnf:
name: "{{ patroni_python39_packages }}"
disablerepo: pgdg*
state: latest

View File

@ -1,44 +1,5 @@
- name: Disable PostgreSQL module - name: Include backup with WAL-G install
shell: dnf module disable -y postgresql include_tasks: wal_g_install.yaml
register: disable_postgresql_module
changed_when: "'Nothing to do' not in disable_postgresql_module.stdout"
- name: "Install EPEL"
dnf:
name: "epel-release"
state: present
- name: Add PostgreSQL repository
dnf:
name: "{{ patroni_postgresql_repo_package }}"
state: present
disable_gpg_check: yes
when: patroni_postgresql_install_repo
- name: "Install PostgreSQL {{ patroni_postgresql_version }}"
dnf:
name: "{{ item }}"
state: present
disable_gpg_check: yes
loop:
- "{{ patroni_postgresql_packages }}"
register: patroni_postgresql_setup
- name: Manage TLS/SSL certificates
include_tasks: cacert.yaml
when: patroni_ssl
- name: Add WAL-G to patroni_create_replica_methods
set_fact:
patroni_create_replica_methods: "{{ patroni_create_replica_methods + [ 'wal_g' ] }}"
when: patroni_wal_g_install
- name: Include WAL-G role
ansible.builtin.include_role:
name: wal-g
vars:
wal_g_pg: yes
when: patroni_wal_g_install
- name: Include Patroni {{ patroni_version }} install - name: Include Patroni {{ patroni_version }} install
include_tasks: install.yaml include_tasks: patroni_install.yaml

View File

@ -0,0 +1,39 @@
- name: Gather packages
package_facts:
manager: auto
- name: Set fact about Patroni package
set_fact:
patroni_installed_package: "{{ ansible_facts.packages[patroni_package_name][0]['name'] }}"
when: patroni_package_name in ansible_facts.packages
- name: Print installed Patroni version
debug:
msg: "{{ ansible_facts.packages[patroni_package_name][0]['version'] }}"
verbosity: 2
when: patroni_installed_package is defined
- name: "Install {{ patroni_package_name }}-{{ patroni_version }}"
dnf:
name: "{{ item }}"
state: present
disable_gpg_check: yes
update_cache: yes
loop:
- "{{ patroni_default_packages }}"
register: patroni_setup
when: patroni_package_name not in ansible_facts.packages
- name: "Update {{ patroni_package_name }}-{{ patroni_version }}"
dnf:
name: "{{ item }}"
state: present
disable_gpg_check: yes
update_cache: yes
loop:
- "{{ patroni_default_packages }}"
register: patroni_update
notify: Restart Patroni
when:
- patroni_package_name in ansible_facts.packages
- ansible_facts.packages[patroni_package_name][0]['version'] != patroni_version|string

View File

@ -0,0 +1,10 @@
- name: "Install EPEL"
dnf:
name: "epel-release"
state: present
- name: Add Patroni repository
dnf:
name: "{{ patroni_repo_package }}"
state: present
disable_gpg_check: yes

View File

@ -0,0 +1,37 @@
- name: Disable PostgreSQL module
shell: dnf module disable -y postgresql
register: disable_postgresql_module
changed_when: "'Nothing to do' not in disable_postgresql_module.stdout"
- name: Gather packages
package_facts:
manager: auto
- name: Set fact about PostgreSQL package
set_fact:
patroni_postgresql_installed_package: "{{ ansible_facts.packages[patroni_postgresql_package_name][0]['name'] }}"
when: patroni_postgresql_package_name in ansible_facts.packages
- name: Print installed PostgreSQL version
debug:
msg: "{{ ansible_facts.packages[patroni_postgresql_package_name][0]['version'] }}"
verbosity: 2
when: patroni_postgresql_installed_package is defined
- name: "Install {{ patroni_postgresql_package_name }}-{{ patroni_postgresql_version }}"
dnf:
name: "{{ item }}"
loop:
- "{{ patroni_postgresql_packages }}"
register: patroni_postgresql_setup
when: patroni_postgresql_package_name not in ansible_facts.packages
- name: "Update {{ patroni_postgresql_package_name }}-{{ patroni_postgresql_version }}"
dnf:
name: "{{ item }}"
loop:
- "{{ patroni_postgresql_packages }}"
register: patroni_postgresql_update
when:
- patroni_postgresql_package_name in ansible_facts.packages
- ansible_facts.packages[patroni_postgresql_package_name][0]['version'] != patroni_postgresql_version|string

View File

@ -1,15 +0,0 @@
- name: Add Patroni repository
dnf:
name: "{{ patroni_repo_package }}"
state: present
disable_gpg_check: yes
- name: "Install Patroni {{ patroni_version }} with Python 3.6"
dnf:
name: "{{ item }}"
state: present
disable_gpg_check: yes
update_cache: yes
loop:
- "{{ patroni_default_packages }}"
register: patroni_setup

View File

@ -1,21 +0,0 @@
- name: Enable Python 3.9 module
shell: dnf module enable -y python39
register: enable_python39_module
changed_when: "'Nothing to do' not in enable_python39_module.stdout"
- name: Install Python 3.9
dnf:
name: python39
state: present
- name: Set python3.9 as python
shell: alternatives --set python /usr/bin/python3.9
register: set_python39_as_python
changed_when: false
failed_when: set_python39_as_python.stdout != ''
- name: "Install Patroni {{ patroni_version }} with Python 3.9"
dnf:
name: "{{ patroni_python39_packages }}"
disablerepo: pgdg*
state: latest

View File

@ -0,0 +1,11 @@
- name: Add WAL-G to patroni_create_replica_methods
set_fact:
patroni_create_replica_methods: "{{ patroni_create_replica_methods + [ 'wal_g' ] }}"
when: patroni_wal_g_install
- name: Include WAL-G role
ansible.builtin.include_role:
name: wal-g
vars:
wal_g_pg: yes
when: patroni_wal_g_install

View File

@ -1,3 +1,17 @@
- name: "Add host to {{ patroni_play_group }} group"
add_host:
groups: "{{ patroni_play_group }}"
hostname: "{{ hostvars[item]['inventory_hostname'] }}"
ansible_host: "{{ hostvars[item]['ansible_host'] | default(omit) }}"
loop: "{{ ansible_play_hosts }}"
when: groups[patroni_play_group] is not defined
changed_when: false
- name: Install python3-cryptography as dependence
package:
name: python3-cryptography
state: present
- name: Check if ssl dir exist - name: Check if ssl dir exist
file: file:
name: "{{ patroni_ssl_path }}" name: "{{ patroni_ssl_path }}"
@ -16,7 +30,7 @@
when: patroni_cert is defined when: patroni_cert is defined
- name: Generate OpenSSL key and cert for Patroni - name: Generate OpenSSL key and cert for Patroni
when: "inventory_hostname == groups.patroni|first" when: "inventory_hostname == groups[patroni_play_group]|first"
block: block:
- name: Generate an OpenSSL private CA key with the default values (4096 bits, RSA) - name: Generate an OpenSSL private CA key with the default values (4096 bits, RSA)
community.crypto.openssl_privatekey: community.crypto.openssl_privatekey:
@ -61,30 +75,26 @@
when: patroni_cert is not defined when: patroni_cert is not defined
register: patroni_key_gen register: patroni_key_gen
- name: Generate subject_alt_ips - name: Generate Patroni subject_alt_ips from ansible_host
set_fact: set_fact:
client_subject_alt_ips: "{{ groups.patroni | map('extract', hostvars, ['ansible_host']) | map('regex_replace', '^', 'IP:') | list }}" patroni_server_subject_alt_ips_from_ansible_host: "{{ groups[patroni_play_group] | default([]) | map('extract', hostvars, ['ansible_host']) | map('regex_replace', '^', 'IP:') | list }}"
when: hostvars[inventory_hostname]['ansible_host'] is defined
- name: Print alt subjects ips - name: Generate Patroni subject_alt_ips from default ipv4 address
debug:
msg: "{{ client_subject_alt_ips }}"
verbosity: 2
- name: Generate subject_alt_names
set_fact: set_fact:
client_subject_alt_names: "{{ groups.patroni | map('extract', hostvars, ['inventory_hostname']) | map('regex_replace', '^', 'DNS:') | list }}" patroni_server_subject_alt_ips: "{{ groups[patroni_play_group] | default([]) | map('extract', hostvars, ['ansible_default_ipv4', 'address']) | map('regex_replace', '^', 'IP:') | list }}"
when: hostvars[inventory_hostname]['ansible_default_ipv4']['address'] is defined
- name: Print alt subjects names - name: Generate Patroni subject_alt_names
debug: set_fact:
msg: "{{ client_subject_alt_names }}" patroni_server_subject_alt_names: "{{ groups[patroni_play_group] | default([]) | map('extract', hostvars, ['inventory_hostname']) | map('regex_replace', '^', 'DNS:') | list }}"
verbosity: 2
- name: Generate an OpenSSL Certificate Signing Request for client - name: Generate an OpenSSL Certificate Signing Request for client
community.crypto.openssl_csr: community.crypto.openssl_csr:
path: "{{ patroni_ssl_path }}/{{ patroni_self_signed_cert_name }}.csr" path: "{{ patroni_ssl_path }}/{{ patroni_self_signed_cert_name }}.csr"
privatekey_path: "{{ patroni_ssl_path }}/{{ patroni_self_signed_cert_name }}.key" privatekey_path: "{{ patroni_ssl_path }}/{{ patroni_self_signed_cert_name }}.key"
common_name: "{{ patroni_self_signed_cert_name }}" common_name: "{{ patroni_self_signed_cert_name }}"
subject_alt_name: "{{ (( groups.patroni | map('extract', hostvars, ['ansible_host']) | map('regex_replace', '^', 'IP:') | list | default([])) + (groups.patroni | map('extract', hostvars, ['inventory_hostname']) | map('regex_replace', '^', 'DNS:') | list | default([]))) }}" subject_alt_name: "{{ patroni_server_subject_alt_ips | default([]) + patroni_server_subject_alt_names | default([]) + patroni_agent_subject_alt_ips | default([]) + patroni_agent_subject_alt_names | default([]) + patroni_server_subject_alt_ips_from_ansible_host | default([]) + patroni_agent_subject_alt_ips_from_ansible_host | default([]) }}"
owner: postgres owner: postgres
group: postgres group: postgres
register: patroni_csr register: patroni_csr
@ -151,13 +161,13 @@
- name: Put Patroni CA OpenSSL cert to PKI - name: Put Patroni CA OpenSSL cert to PKI
copy: copy:
content: "{{ patroni_ca_cert }}" content: "{{ patroni_ca_cert }}"
dest: "/etc/pki/ca-trust/source/anchors/CA-{{ patroni_self_signed_cert_name }}.crt" dest: "{{ patroni_ssl_ca_trust_dir }}/CA-{{ patroni_self_signed_cert_name }}.crt"
register: ca_trust_anchors register: ca_trust
notify: Restart Patroni notify: Restart Patroni
- name: Update CA trust - name: Update CA trust
shell: update-ca-trust extract shell: "{{ patroni_ssl_update_ca_command }}"
when: ca_trust_anchors.changed when: ca_trust.changed
- name: Put Patroni OpenSSL key - name: Put Patroni OpenSSL key
copy: copy:

View File

@ -30,7 +30,7 @@
- name: Propagate Patroni config - name: Propagate Patroni config
copy: copy:
content: "{{ patroni_config_combined | to_nice_yaml }}" content: "{{ patroni_config_combined | to_nice_yaml }}"
dest: "/etc/patroni/patroni.yml" dest: "/etc/patroni/{{ patroni_config_name }}"
owner: "postgres" owner: "postgres"
group: "postgres" group: "postgres"
mode: 0644 mode: 0644

42
tasks/locale.yaml Normal file
View File

@ -0,0 +1,42 @@
- name: Install glibc-all-langpacks for RedHat
dnf:
name: glibc-all-langpacks
state: present
when: ansible_facts['os_family'] == 'RedHat'
- name: Check if locale exists
shell: "locale -a | grep -i {{ patroni_postgresql_system_locale | regex_replace('-', '') | quote }}"
register: found_locale
changed_when: false
failed_when: false
- name: Create locale
command: "localedef -i {{ patroni_postgresql_system_locale | regex_replace('(.*)\\..*', '\\1') | quote }} -f {{ patroni_postgresql_system_locale | regex_replace('.*\\.(.*)', '\\1') | quote }} {{ patroni_postgresql_system_locale | quote }}"
when: not ansible_check_mode and found_locale.rc != 0
- name: Check if language exists
shell: "locale -a | grep -i {{ patroni_postgresql_system_language | regex_replace('-', '') | quote }}"
register: found_language
changed_when: false
failed_when: false
- name: Create language
command: "localedef -i {{ patroni_postgresql_system_language | regex_replace('(.*)\\..*', '\\1') | quote }} -f {{ patroni_postgresql_system_language | regex_replace('.*\\.(.*)', '\\1') | quote }} {{ patroni_postgresql_system_language | quote }}"
when: not ansible_check_mode and found_language.rc != 0
- name: Get current locale and language configuration
command: localectl status
register: locale_status
changed_when: false
- name: Parse 'LANG' from current locale and language configuration
set_fact:
locale_lang: "{{ locale_status.stdout | regex_search('LANG=([^\n]+)', '\\1') | first }}"
- name: Parse 'LANGUAGE' from current locale and language configuration
set_fact:
locale_language: "{{ locale_status.stdout | regex_search('LANGUAGE=([^\n]+)', '\\1') | default([locale_lang], true) | first }}"
- name: Configure locale to '{{ patroni_postgresql_system_locale }}' and language to '{{ patroni_postgresql_system_language }}'
command: localectl set-locale LANG={{ patroni_postgresql_system_locale }} LANGUAGE={{ patroni_postgresql_system_language }}
changed_when: locale_lang != patroni_postgresql_system_locale or locale_language != patroni_postgresql_system_language

View File

@ -6,33 +6,39 @@
vars: vars:
params: params:
files: 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['distribution'] }}.yaml"
- "{{ ansible_facts['os_family'] }}.yaml" - "{{ ansible_facts['os_family'] }}.yaml"
paths: paths:
- "vars" - "vars"
tags: always, patroni_vars tags: patroni_vars
- name: Load host variables to override role vars - name: Set facts about needed vars
include_vars: set_fact:
dir: "{{ inventory_dir }}/host_vars" patroni_postgresql_home_dir: "{{ patroni_postgresql_home_dir }}"
ignore_unknown_extensions: True patroni_postgresql_data_dir: "{{ patroni_postgresql_data_dir }}"
extensions:
- ''
- "yaml"
- "yml"
tags: patroni_override_role_vars
- name: Load group variables to override role vars - name: "Set locale for PostgreSQL"
include_vars: include_tasks: locale.yaml
dir: "{{ inventory_dir }}/group_vars" tags: patroni_locale
ignore_unknown_extensions: True
extensions:
- ''
- "yaml"
- "yml"
tags: patroni_override_role_vars
- name: Task name - name: "Install Patroni repository and deps for {{ ansible_facts['os_family'] }}"
include_tasks: "{{ ansible_facts['os_family'] }}/patroni_repos_and_deps.yaml"
when: patroni_install_official_repo
tags: patroni_repos_and_deps
- name: "Install PostgreSQL for {{ ansible_facts['os_family'] }}"
include_tasks: "{{ ansible_facts['os_family'] }}/postgresql_install.yaml"
tags: patroni_install
- name: "Manage TLS/SSL certificates"
include_tasks: cacert.yaml
when: patroni_ssl
- name: "Check if patroni.yaml exist"
stat: stat:
path: /etc/patroni/patroni.yaml path: /etc/patroni/patroni.yaml
register: patroni_config register: patroni_config
@ -59,7 +65,6 @@
- name: "Dynamic Patroni configuration" - name: "Dynamic Patroni configuration"
include_tasks: dynamic_config.yaml include_tasks: dynamic_config.yaml
when: when:
#- patroni_config.stat.exists
- patroni_postgresql_dynamic_parameters - patroni_postgresql_dynamic_parameters
tags: patroni_dynamic_configure tags: patroni_dynamic_configure

View File

@ -124,10 +124,10 @@ postgresql:
listen: {{ hostvars[inventory_hostname]['ansible_host'] }},127.0.0.1:{{ patroni_postgresql_port }} listen: {{ hostvars[inventory_hostname]['ansible_host'] }},127.0.0.1:{{ patroni_postgresql_port }}
connect_address: {{ hostvars[inventory_hostname]['ansible_host'] }}:{{ patroni_postgresql_port }} connect_address: {{ hostvars[inventory_hostname]['ansible_host'] }}:{{ patroni_postgresql_port }}
use_unix_socket: true use_unix_socket: true
data_dir: /var/lib/pgsql/{{ patroni_postgresql_major_version }}/data data_dir: {{ patroni_postgresql_home_dir }}/{{ patroni_postgresql_major_version }}/data
bin_dir: /usr/pgsql-{{ patroni_postgresql_major_version }}/bin bin_dir: {{ patroni_postgresql_bin_dir }}
config_dir: /var/lib/pgsql/{{ patroni_postgresql_major_version }}/data config_dir: {{ patroni_postgresql_home_dir }}/{{ patroni_postgresql_major_version }}/data
pgpass: /var/lib/pgsql/.pgpass_patroni pgpass: {{ patroni_postgresql_home_dir }}/.pgpass_patroni
authentication: authentication:
replication: replication:
username: {{ patroni_replication_username }} username: {{ patroni_replication_username }}

40
vars/Debian-11.yaml Normal file
View File

@ -0,0 +1,40 @@
patroni_apt_key:
- name: org.postgresql.gpg
url: "https://www.postgresql.org/media/keys/ACCC4CF8.asc"
keyring: /etc/apt/trusted.gpg.d/org.postgresql.gpg
patroni_apt_repository:
- repo: deb http://apt.postgresql.org/pub/repos/apt {{ ansible_distribution_release }}-pgdg main
filename: postgresql
patroni_deps_packages:
- gnupg
- python3-psycopg2
- python3-consul
- python3-zookeeper
- python3-etcd
# Patroni variables
patroni_package_name: "patroni"
patroni_package: "{{ patroni_package_name }}={{ patroni_version }}-{{ patroni_version_build }}"
patroni_version_build: "1.pgdg110+1"
patroni_unit_name: "patroni"
patroni_config_name: "config.yml"
# PostgreSQL variables
patroni_postgresql_package_name: "postgresql-{{ patroni_postgresql_major_version }}"
patroni_postgresql_package: "{{ patroni_postgresql_package_name }}={{ patroni_postgresql_version }}-{{ patroni_postgresql_version_build }}"
patroni_postgresql_version_build: "1.pgdg110+1"
patroni_postgresql_cluster_name: "main"
patroni_postgresql_data_dir: "/var/lib/postgresql/{{ patroni_postgresql_major_version }}/{{ patroni_postgresql_cluster_name }}"
patroni_postgresql_wal_dir: ""
patroni_postgresql_conf_dir: "/etc/postgresql/{{ patroni_postgresql_major_version }}/{{ patroni_postgresql_cluster_name }}"
patroni_postgresql_bin_dir: "/usr/lib/postgresql/{{ patroni_postgresql_major_version }}/bin"
patroni_postgresql_log_dir: "/var/log/postgresql"
patroni_postgresql_unix_socket_dir: "/var/run/postgresql"
patroni_postgresql_home_dir: "/var/lib/postgresql"
patroni_postgresql_bin_dir: "/usr/lib/postgresql/{{ patroni_postgresql_major_version }}/bin"
patroni_postgresql_unit_name: "postgresql@{{ patroni_postgresql_major_version}}-{{ patroni_postgresql_cluster_name }}"
# SSL variables
patroni_ssl_update_ca_command: "update-ca-certificates --fresh"
patroni_ssl_ca_trust_dir: "/usr/local/share/ca-certificates"

View File

@ -1,21 +0,0 @@
patroni_apt_key:
- name: org.postgresql.gpg
url: "https://www.postgresql.org/media/keys/ACCC4CF8.asc"
keyring: /etc/apt/trusted.gpg.d/org.postgresql.gpg
patroni_apt_repository:
- repo: deb http://apt.postgresql.org/pub/repos/apt {{ ansible_distribution_release }}-pgdg main
filename: postgresql
patroni_postgresql_package: "{{ patroni_postgresql_package_name }}-{{ patroni_postgresql_major_version }}={{ patroni_postgresql_version }}"
patroni_package: "{{ patroni_package_name }}={{ patroni_version }}"
# PostgreSQL variables
patroni_postgresql_cluster_name: "main"
patroni_postgresql_data_dir: "{{ patroni_postgresql_home_dir }}/{{ patroni_postgresql_major_version }}/{{ patroni_postgresql_cluster_name }}" # You can specify custom data dir path
patroni_postgresql_wal_dir: "" # custom WAL dir path (symlink will be created) [optional]
patroni_postgresql_conf_dir: "/etc/postgresql/{{ patroni_postgresql_major_version }}/{{ patroni_postgresql_cluster_name }}"
patroni_postgresql_bin_dir: "/usr/lib/postgresql/{{ patroni_postgresql_major_version }}/bin"
patroni_postgresql_log_dir: "/var/log/postgresql"
patroni_postgresql_unix_socket_dir: "/var/run/postgresql"
patroni_postgresql_home_dir: "/var/lib/postgresql"

View File

@ -10,55 +10,24 @@ patroni_default_packages:
- "{{ patroni_package_name }}-etcd-{{ patroni_version }}" - "{{ patroni_package_name }}-etcd-{{ patroni_version }}"
- "{{ patroni_package_name }}-zookeeper-{{ patroni_version }}" - "{{ patroni_package_name }}-zookeeper-{{ patroni_version }}"
patroni_python39_packages: # Patroni variables
- "{{ patroni_package_name }}-{{ patroni_version }}" patroni_package_name: "patroni"
- python39-consul patroni_package: "{{ patroni_package_name }}-{{ patroni_version }}"
- python39-etcd patroni_unit_name: "patroni"
- python3.9 patroni_config_name: "patroni.yml"
- python39-six
- python39-aio-pika
- python39-aiodns
- python39-aiohttp
- python39-aiormq
- python39-aiosignal
- python39-async-timeout
- python39-attrs
- python39-brotli
- python39-cchardet
- python39-certifi
- python39-cffi
- python39-chardet
- python39-charset-normalizer
- python39-click
- python39-consul
- python39-dnspython
- python39-dotenv
- python39-etcd
- python39-frozenlist
- python39-idna
- python39-multidict
- python39-pamqp
- python39-ply
- python39-prettytable
- python39-psutil
- python39-psycopg2
- python39-pycares
- python39-pycparser
- python39-pydantic
- python39-pysocks
- python39-pyyaml
- python39-requests
- python39-typing-extensions
- python39-urllib3
- python39-wcwidth
- python39-yarl
- python39-ydiff
- python39-dateutil
patroni_postgresql_data_dir: "{{ patroni_postgresql_home_dir }}/{{ patroni_postgresql_major_version }}/data" # You can specify custom data dir path # PostgreSQL variables
patroni_postgresql_wal_dir: "" # custom WAL dir path (symlink will be created) [optional] patroni_postgresql_package_name: "postgresql"
patroni_postgresql_package: "{{ patroni_postgresql_package_name }}-{{ patroni_postgresql_version }}"
patroni_postgresql_data_dir: "{{ patroni_postgresql_home_dir }}/{{ patroni_postgresql_major_version }}/data"
patroni_postgresql_wal_dir: ""
patroni_postgresql_conf_dir: "{{ patroni_postgresql_data_dir }}" patroni_postgresql_conf_dir: "{{ patroni_postgresql_data_dir }}"
patroni_postgresql_bin_dir: "/usr/pgsql-{{ patroni_postgresql_version }}/bin"
patroni_postgresql_log_dir: "/var/log/postgresql" patroni_postgresql_log_dir: "/var/log/postgresql"
patroni_postgresql_unix_socket_dir: "/var/run/postgresql" patroni_postgresql_unix_socket_dir: "/var/run/postgresql"
patroni_postgresql_home_dir: "/var/lib/pgsql" patroni_postgresql_home_dir: "/var/lib/pgsql"
patroni_postgresql_bin_dir: "/usr/pgsql-{{ patroni_postgresql_major_version }}/bin"
patroni_postgresql_unit_name: "postgresql-{{ patroni_postgresql_major_version }}"
# SSL variables
patroni_ssl_update_ca_command: "update-ca-trust extract"
patroni_ssl_ca_trust_dir: "/etc/pki/ca-trust/source/anchors"

40
vars/Ubuntu-20.04.yaml Normal file
View File

@ -0,0 +1,40 @@
patroni_apt_key:
- name: org.postgresql.gpg
url: "https://www.postgresql.org/media/keys/ACCC4CF8.asc"
keyring: /etc/apt/trusted.gpg.d/org.postgresql.gpg
patroni_apt_repository:
- repo: deb http://apt.postgresql.org/pub/repos/apt {{ ansible_distribution_release }}-pgdg main
filename: postgresql
patroni_deps_packages:
- gnupg
- python3-psycopg2
- python3-consul
- python3-zookeeper
- python3-etcd
# Patroni variables
patroni_package_name: "patroni"
patroni_package: "{{ patroni_package_name }}={{ patroni_version }}-{{ patroni_version_build }}"
patroni_version_build: "1.pgdg20.04+1"
patroni_unit_name: "patroni"
patroni_config_name: "config.yml"
# PostgreSQL variables
patroni_postgresql_package_name: "postgresql-{{ patroni_postgresql_major_version }}"
patroni_postgresql_package: "{{ patroni_postgresql_package_name }}={{ patroni_postgresql_version }}-{{ patroni_postgresql_version_build }}"
patroni_postgresql_version_build: "1.pgdg20.04+1"
patroni_postgresql_cluster_name: "main"
patroni_postgresql_data_dir: "/var/lib/postgresql/{{ patroni_postgresql_major_version }}/{{ patroni_postgresql_cluster_name }}"
patroni_postgresql_wal_dir: ""
patroni_postgresql_conf_dir: "/etc/postgresql/{{ patroni_postgresql_major_version }}/{{ patroni_postgresql_cluster_name }}"
patroni_postgresql_bin_dir: "/usr/lib/postgresql/{{ patroni_postgresql_major_version }}/bin"
patroni_postgresql_log_dir: "/var/log/postgresql"
patroni_postgresql_unix_socket_dir: "/var/run/postgresql"
patroni_postgresql_home_dir: "/var/lib/postgresql"
patroni_postgresql_bin_dir: "/usr/lib/postgresql/{{ patroni_postgresql_major_version }}/bin"
patroni_postgresql_unit_name: "postgresql@{{ patroni_postgresql_major_version}}-{{ patroni_postgresql_cluster_name }}"
# SSL variables
patroni_ssl_update_ca_command: "update-ca-certificates --fresh"
patroni_ssl_ca_trust_dir: "/usr/local/share/ca-certificates"

40
vars/Ubuntu-22.04.yaml Normal file
View File

@ -0,0 +1,40 @@
patroni_apt_key:
- name: org.postgresql.gpg
url: "https://www.postgresql.org/media/keys/ACCC4CF8.asc"
keyring: /etc/apt/trusted.gpg.d/org.postgresql.gpg
patroni_apt_repository:
- repo: deb http://apt.postgresql.org/pub/repos/apt {{ ansible_distribution_release }}-pgdg main
filename: postgresql
patroni_deps_packages:
- gnupg
- python3-psycopg2
- python3-consul
- python3-zookeeper
- python3-etcd
# Patroni variables
patroni_package_name: "patroni"
patroni_package: "{{ patroni_package_name }}={{ patroni_version }}-{{ patroni_version_build }}"
patroni_version_build: "1.pgdg22.04+1"
patroni_unit_name: "patroni"
patroni_config_name: "config.yml"
# PostgreSQL variables
patroni_postgresql_package_name: "postgresql-{{ patroni_postgresql_major_version }}"
patroni_postgresql_package: "{{ patroni_postgresql_package_name }}={{ patroni_postgresql_version }}-{{ patroni_postgresql_version_build }}"
patroni_postgresql_version_build: "1.pgdg22.04+1"
patroni_postgresql_cluster_name: "main"
patroni_postgresql_data_dir: "/var/lib/postgresql/{{ patroni_postgresql_major_version }}/{{ patroni_postgresql_cluster_name }}"
patroni_postgresql_wal_dir: ""
patroni_postgresql_conf_dir: "/etc/postgresql/{{ patroni_postgresql_major_version }}/{{ patroni_postgresql_cluster_name }}"
patroni_postgresql_bin_dir: "/usr/lib/postgresql/{{ patroni_postgresql_major_version }}/bin"
patroni_postgresql_log_dir: "/var/log/postgresql"
patroni_postgresql_unix_socket_dir: "/var/run/postgresql"
patroni_postgresql_home_dir: "/var/lib/postgresql"
patroni_postgresql_bin_dir: "/usr/lib/postgresql/{{ patroni_postgresql_major_version }}/bin"
patroni_postgresql_unit_name: "postgresql@{{ patroni_postgresql_major_version}}-{{ patroni_postgresql_cluster_name }}"
# SSL variables
patroni_ssl_update_ca_command: "update-ca-certificates --fresh"
patroni_ssl_ca_trust_dir: "/usr/local/share/ca-certificates"