From 5cb37620807ac0cc5e79315e0c95ff44ee72a6c9 Mon Sep 17 00:00:00 2001 From: Jeremy Lecour Date: Fri, 12 May 2023 18:12:06 +0200 Subject: [PATCH] WIP: use the systemd unit and config conventions of Patroni 3 --- patroni/tasks/config.yml | 21 ++++-------- .../{patroni.conf.j2 => config.yml.j2} | 34 +++++++++---------- patroni/templates/patroni.service.j2 | 17 ---------- 3 files changed, 24 insertions(+), 48 deletions(-) rename patroni/templates/{patroni.conf.j2 => config.yml.j2} (56%) delete mode 100644 patroni/templates/patroni.service.j2 diff --git a/patroni/tasks/config.yml b/patroni/tasks/config.yml index 4d44e285..9d813d60 100644 --- a/patroni/tasks/config.yml +++ b/patroni/tasks/config.yml @@ -2,25 +2,18 @@ - name: Create a password for PostgreSQL repl user command: "apg -M LCN -n1 -m 16" - register: postgresql_replication_password + register: patroni_postgresql_replication_password + check_mode: no - name: Create a password for PostgreSQL superuser user command: "apg -M LCN -n1 -m 16" - register: postgresql_superuser_password + register: patroni_postgresql_superuser_password + check_mode: no - name: Create Patroni config file ansible.builtin.template: - src: patroni.conf.j2 - dest: /etc/patroni/config-{{ cluster_name }}.yml + src: config.j2 + dest: /etc/patroni/config.yml owner: root group: root - mode: "0644" - -- mane: Create Systemd Unit for Patroni - ansible.builtin.template: - src: patroni.service.j2 - dest: /etc/systemd/system/patroni.service - owner: root - group: root - mode: "0644" - + mode: "0644" \ No newline at end of file diff --git a/patroni/templates/patroni.conf.j2 b/patroni/templates/config.yml.j2 similarity index 56% rename from patroni/templates/patroni.conf.j2 rename to patroni/templates/config.yml.j2 index 2dc23a28..178435e6 100644 --- a/patroni/templates/patroni.conf.j2 +++ b/patroni/templates/config.yml.j2 @@ -1,9 +1,9 @@ -scope: {{ cluster_name }} -name: {{ cluster_name_host }} +scope: {{ patroni_scope }} +name: {{ patroni_name }} restapi: - listen: {{ patroni_restapi_listen }}:{{ patroni_restapi_port }} - connect_address: {{ patroni_restapi_listen }}:{{ patroni_restapi_port }} + listen: {{ patroni_restapi_listen }} + connect_address: {{ patroni_restapi_connect_address }} etcd: hosts: @@ -40,29 +40,29 @@ bootstrap: - host all all 0.0.0.0/0 md5 users: - {{ postgresql_superuser }}: - password: {{ postgresql_superuser_password.stdout }} + {{ patroni_postgresql_superuser }}: + password: {{ patroni_postgresql_superuser_password.stdout }} options: - createrole - createdb - {{ postgresql_replication_user }}: - password: {{ postgresql_replication_password.stdout }} + {{ patroni_postgresql_replication_user }}: + password: {{ patroni_postgresql_replication_password.stdout }} options: - replication postgresql: - listen: {{ postgresql_listen_ips }}:{{ postgresql_port }} - connect_address: {{ postgresql_connect_ip }}:{{ postgresql_port }} - bin_dir: /usr/lib/postgresql/{{ postgresql_version }}/bin/ - data_dir: /home/{{ cluster_name_host }} - pgpass: /tmp/{{ cluster_name_host }}-pgpass + listen: {{ patroni_postgresql_listen }} + connect_address: {{ patroni_postgresql_connect_address }} + bin_dir: /usr/lib/postgresql/{{ patroni_postgresql_version }}/bin/ + data_dir: {{ patroni_postgresql_datadir }} + pgpass: {{ patroni_postgresql_pgpass }} authentication: replication: - username: {{ postgresql_replication_user }} - password: {{ postgresql_replication_password.stdout }} + username: {{ patroni_postgresql_replication_user }} + password: {{ patroni_postgresql_replication_password.stdout }} superuser: - username: {{ postgresql_superuser }} - password: {{ postgresql_superuser_password.stdout }} + username: {{ patroni_postgresql_superuser }} + password: {{ patroni_postgresql_superuser_password.stdout }} parameters: unix_socket_directories: '/tmp' diff --git a/patroni/templates/patroni.service.j2 b/patroni/templates/patroni.service.j2 deleted file mode 100644 index 6f9e1521..00000000 --- a/patroni/templates/patroni.service.j2 +++ /dev/null @@ -1,17 +0,0 @@ -[Unit] -Description=Runners to orchestrate a high-availability PostgreSQL -After=syslog.target network.target - -[Service] -Type=simple - -User=postgres -Group=postgres - -ExecStart=/usr/bin/patroni /etc/patroni/config-{{ cluster_name }}.yml -KillMode=process -TimeoutSec=30 -Restart=no - -[Install] -WantedBy=multi-user.targ