diff --git a/roles/postgres-ha/handlers/main.yml b/roles/postgres-ha/handlers/main.yml index ba20097f70db795356d34c1412bc5492d7c143e1..6b60369e5e0af7c27e2559489ca84e47274eca17 100644 --- a/roles/postgres-ha/handlers/main.yml +++ b/roles/postgres-ha/handlers/main.yml @@ -1,5 +1,9 @@ --- +- name: reload systemd + systemd: + daemon_reload: true + - name: restart postgresql systemd: name: postgresql@{{ repmgr_pg_version }}-{{ repmgr_pg_cluster }} @@ -10,4 +14,9 @@ name: repmgrd state: restarted +- name: restart rephacheck + systemd: + name: rephacheck.socket + state: restarted + ... diff --git a/roles/postgres-ha/tasks/main.yml b/roles/postgres-ha/tasks/main.yml index 7ca4b71ea3cb6d3ac99d92711a747981f1304704..8092f18e83c7bc29ad87f6949458d89e25dff540 100644 --- a/roles/postgres-ha/tasks/main.yml +++ b/roles/postgres-ha/tasks/main.yml @@ -84,9 +84,9 @@ replace: '{{ item.key }}={{ item.value }}' - name: copy events notification script - copy: - src: repmgr-event.py - dest: /usr/local/bin/repmgr-event + template: + src: repmgr-event.py.j2 + dest: /usr/bin/repmgr-event mode: 0755 - name: configure sudo @@ -268,8 +268,8 @@ # REPHACHECK - name: install rephacheck - copy: - src: rephacheck.py + template: + src: rephacheck.py.j2 dest: /usr/bin/rephacheck mode: 0755 @@ -281,12 +281,15 @@ - name: configure rephacheck template: src: rephacheck.conf.j2 - dest: /etc/postgresql/11/main/rephacheck.conf + dest: /etc/postgresql/{{ repmgr_pg_version }}/{{ repmgr_pg_cluster }}/rephacheck.conf owner: postgres group: postgres mode: 0644 - name: configure rephacheck socket + notify: + - reload systemd + - restart rephacheck copy: dest: /etc/systemd/system/rephacheck.socket content: | @@ -301,6 +304,9 @@ WantedBy=sockets.target - name: configure rephacheck service + notify: + - reload systemd + - restart rephacheck copy: dest: /etc/systemd/system/rephacheck@.service content: | diff --git a/roles/postgres-ha/files/rephacheck.py b/roles/postgres-ha/templates/rephacheck.py.j2 similarity index 93% rename from roles/postgres-ha/files/rephacheck.py rename to roles/postgres-ha/templates/rephacheck.py.j2 index 34f7c7eb2a6b69a3ca950a8e7ec54c787bdd958b..7ec6cfea94d9197c1b28ecbb5432c21fbb5ec706 100644 --- a/roles/postgres-ha/files/rephacheck.py +++ b/roles/postgres-ha/templates/rephacheck.py.j2 @@ -50,7 +50,7 @@ def get_quorum_state(node_id): if __name__ == '__main__': - with open('/etc/postgresql/11/main/rephacheck.conf') as rephaconf: + with open('/etc/postgresql/{{ repmgr_pg_version }}/{{ repmgr_pg_cluster }}/rephacheck.conf') as rephaconf: conf = toml.load(rephaconf) NODES = conf.get('nodes') diff --git a/roles/postgres-ha/files/repmgr-event.py b/roles/postgres-ha/templates/repmgr-event.py.j2 similarity index 94% rename from roles/postgres-ha/files/repmgr-event.py rename to roles/postgres-ha/templates/repmgr-event.py.j2 index e95a1befc656197c2217a12714650aaf2bd9eb02..de85cebc85c03b3a6b57fc2aa2ea3aa9f34431b5 100755 --- a/roles/postgres-ha/files/repmgr-event.py +++ b/roles/postgres-ha/templates/repmgr-event.py.j2 @@ -36,7 +36,7 @@ def main(): # load config if exists try: - with open("/etc/postgresql/11/main/repmgr-event.json") as data_file: + with open("/etc/postgresql/{{ repmgr_pg_version }}/{{ repmgr_pg_cluster }}/repmgr-event.json") as data_file: data = json.load(data_file) except EnvironmentError: data = {} diff --git a/roles/postgres-ha/templates/repmgr.conf.j2 b/roles/postgres-ha/templates/repmgr.conf.j2 index 2cd1dc39da5ae3de1563220af0bed80ad4cc81d2..7934ba59039d3ef5a906db38900b6aa2e9d6c05f 100644 --- a/roles/postgres-ha/templates/repmgr.conf.j2 +++ b/roles/postgres-ha/templates/repmgr.conf.j2 @@ -3,7 +3,7 @@ node_name={{ repmgr_node_name }} conninfo='{{ repmgr_conninfo }}' data_directory=/var/lib/postgresql/{{ repmgr_pg_version }}/{{ repmgr_pg_cluster }} use_replication_slots=1 -event_notification_command='/usr/local/bin/repmgr-event %n %e %s "%t" "%d"' +event_notification_command='/usr/bin/repmgr-event %n %e %s "%t" "%d"' pg_bindir=/usr/lib/postgresql/{{ repmgr_pg_version }}/bin/ pg_ctl_options='-s' pg_basebackup_options='--label=repmgr_backup' @@ -11,8 +11,8 @@ primary_follow_timeout=30 failover=automatic reconnect_attempts=6 reconnect_interval=5 -promote_command='repmgr standby promote' -follow_command='repmgr standby follow -W' +promote_command='repmgr -f {{ repmgr_config }} standby promote' +follow_command='repmgr -f {{ repmgr_config }} standby follow -W' service_start_command='sudo systemctl start postgresql@{{ repmgr_pg_version }}-{{ repmgr_pg_cluster }}' service_stop_command='sudo systemctl stop postgresql@{{ repmgr_pg_version }}-{{ repmgr_pg_cluster }}' service_restart_command='sudo systemctl restart postgresql@{{ repmgr_pg_version }}-{{ repmgr_pg_cluster }}'