Skip to content

Commit

Permalink
Merge branch 'master' into cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
vitabaks committed Feb 2, 2024
2 parents e9e0bc6 + 8c78432 commit 197bf92
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 27 deletions.
4 changes: 4 additions & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
ansible.builtin.set_fact:
target: system # includes updates to Postgres, Patroni, and all system packages

- name: Add repository GPG key
ansible.builtin.command: "rpm --import https://repo.almalinux.org/almalinux/RPM-GPG-KEY-AlmaLinux-{{ ansible_distribution_major_version }}"
when: ansible_distribution == "AlmaLinux"

- name: Clean yum cache (molecule containers)
ansible.builtin.command: yum clean all
when:
Expand Down
4 changes: 4 additions & 0 deletions molecule/pg_upgrade/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
pg_old_version: "14"
pg_new_version: "16"

- name: Add repository GPG key
ansible.builtin.command: "rpm --import https://repo.almalinux.org/almalinux/RPM-GPG-KEY-AlmaLinux-{{ ansible_distribution_major_version }}"
when: ansible_distribution == "AlmaLinux"

- name: Clean yum cache (molecule containers)
ansible.builtin.command: yum clean all
when:
Expand Down
11 changes: 0 additions & 11 deletions roles/add-repository/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,6 @@
when: yum_repository | length > 0

# Install Epel Repository
- name: Remove epel-release package (if exists)
ansible.builtin.package:
name: epel-release
state: absent
register: package_status
until: package_status is success
delay: 5
retries: 3
when: install_epel_repo|bool
tags: install_epel_repo

- name: Get epel-release-latest rpm package
ansible.builtin.get_url:
url: "https://dl.fedoraproject.org/pub/epel/epel-release-latest-{{ ansible_distribution_major_version }}.noarch.rpm"
Expand Down
1 change: 1 addition & 0 deletions roles/etcd/templates/etcd.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ ETCD_DATA_DIR="{{ etcd_data_dir }}"
ETCD_ELECTION_TIMEOUT="5000"
ETCD_HEARTBEAT_INTERVAL="1000"
ETCD_INITIAL_ELECTION_TICK_ADVANCE="false"
ETCD_AUTO_COMPACTION_RETENTION="1"
37 changes: 22 additions & 15 deletions roles/pgbouncer/config/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,33 @@
tags: pgbouncer, pgbouncer_conf, pgbouncer_generate_userlist

# if pgbouncer_auth_user is 'true'
- name: "Create function 'user_search' for pgbouncer 'auth_query' option in all databases"
become: true
become_user: postgres
ansible.builtin.shell: |
for db in $({{ postgresql_bin_dir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc \
"select datname from pg_catalog.pg_database where datname <> 'template0'"); do
{{ postgresql_bin_dir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d "$db" -tAXc '
CREATE OR REPLACE FUNCTION user_search(uname TEXT) RETURNS TABLE (usename name, passwd text) AS
- block:
- name: "Check if 'user_search' function exists"
become: true
become_user: postgres
ansible.builtin.command: >-
{{ postgresql_bin_dir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d {{ pgbouncer_auth_dbname }} -tAXc
"select exists(select proname from pg_proc where proname='user_search')"
register: exists_func_user
when: (is_master | bool and patroni_standby_cluster.host | default('') | length < 1) # do not perform on the Standby Cluster leader
changed_when: false

- name: "Create 'user_search' function for pgbouncer 'auth_query' option"
become: true
become_user: postgres
ansible.builtin.command: >-
{{ postgresql_bin_dir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d {{ pgbouncer_auth_dbname }} -tAXc
"CREATE FUNCTION user_search(uname TEXT) RETURNS TABLE (usename name, passwd text) AS
$$
SELECT usename, passwd FROM pg_shadow WHERE usename=$1;
$$
LANGUAGE sql SECURITY DEFINER;
REVOKE ALL ON FUNCTION user_search(uname TEXT) FROM public;
GRANT EXECUTE ON FUNCTION user_search(uname TEXT) TO {{ pgbouncer_auth_username }};
'; done
args:
executable: /bin/bash
when:
- pgbouncer_auth_user | bool
- (is_master | bool and patroni_standby_cluster.host | default('') | length < 1) # do not perform on the Standby Cluster leader
GRANT EXECUTE ON FUNCTION user_search(uname TEXT) TO {{ pgbouncer_auth_username }}"
when:
- (is_master | bool and patroni_standby_cluster.host | default('') | length < 1) # do not perform on the Standby Cluster leader
- exists_func_user.stdout == "f"
when: pgbouncer_auth_user|bool
tags: pgbouncer, pgbouncer_conf, pgbouncer_auth_query

...
2 changes: 1 addition & 1 deletion vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ keepalived_virtual_router_id: "{{ cluster_vip.split('.')[3] | int }}" # The last
# virtual_router_id - must be unique in the network (available values are 0..255).

# vip-manager (if 'cluster_vip' is specified and 'with_haproxy_load_balancing' is 'false')
vip_manager_version: "2.1.0" # version to install
vip_manager_version: "2.3.0" # version to install
vip_manager_conf: "/etc/patroni/vip-manager.yml"
vip_manager_interval: "1000" # time (in milliseconds) after which vip-manager wakes up and checks if it needs to register or release ip addresses.
vip_manager_iface: "{{ vip_interface }}" # interface to which the virtual ip will be added
Expand Down

0 comments on commit 197bf92

Please sign in to comment.