@ -5,20 +5,17 @@
become_user : postgres
shell : "/usr/bin/psql -Atc \"SELECT count(rolname) FROM pg_roles where rolname='replicator'\"" # noqa command-instead-of-shell
register : role_check
ignore_errors : yes # noqa ignore-errors no-changed-when
- name : Create role if necessary
become : yes
become_user : postgres
shell : "/usr/bin/psql -c 'CREATE ROLE replicator WITH REPLICATION LOGIN;'"
when : role_check.stdout == "0"
ignore_errors : yes # noqa ignore-errors
- name : Change password with scram-sha-256! for replicator and set password
become : yes
become_user : postgres
shell : "/usr/bin/psql -c \"set password_encryption = 'scram-sha-256';ALTER ROLE replicator WITH PASSWORD '{{ postgres_replicator_user_password }}';\""
ignore_errors : yes # noqa ignore-errors no-changed-when
- name : Setup pg_hba.conf for replicator user
lineinfile:
@ -111,32 +108,27 @@
become_user : postgres
shell : "/usr/bin/psql -Atc \"SELECT count(*) FROM pg_database WHERE datname = 'replication_cron'\""
register : database_replication_check
ignore_errors : yes # noqa ignore-errors no-changed-when
- name : Create replication_cron update database
become : yes
become_user : postgres
shell : "/usr/bin/psql -c \"CREATE DATABASE replication_cron;\""
when : database_replication_check.stdout == "0"
ignore_errors : yes # noqa ignore-errors no-changed-when
- name : Create replication update schema
become : yes
become_user : postgres
shell : "/usr/bin/psql replication_cron -c \"CREATE SCHEMA IF NOT EXISTS replication_cron;\""
ignore_errors : yes # noqa ignore-errors no-changed-when
- name : Create replication update table
become : yes
become_user : postgres
shell : "/usr/bin/psql replication_cron -c \"CREATE TABLE IF NOT EXISTS replication_cron.replication_cron (dt timestamp);\""
ignore_errors : yes # noqa ignore-errors no-changed-when
- name : Create dummy update data
become : yes
become_user : postgres
shell : "/usr/bin/psql replication_cron -c \"INSERT INTO replication_cron.replication_cron SELECT now() WHERE NOT EXISTS (SELECT 1 from replication_cron.replication_cron);\""
ignore_errors : yes # noqa ignore-errors no-changed-when
- name : Ensure a cron runs every 5 minutes and update replication check table"
ansible.builtin.cron:
@ -149,16 +141,13 @@
become_user : postgres
shell : "/usr/bin/psql -Atc \"select count(*) from pg_replication_slots where slot_name='pgstandby1'\""
register : replication_slot_check
ignore_errors : yes # noqa ignore-errors no-changed-when
- name : Create replication-slot
become : yes
become_user : postgres
shell : "/usr/bin/psql -Atc \"SELECT pg_create_physical_replication_slot('pgstandby1');\""
ignore_errors : yes # noqa ignore-errors
when : replication_slot_check.stdout == "0"
# only needed in case of install from scratch
- name : "Ensure test db stuff"
block:
@ -185,5 +174,4 @@
name : dummytestdb
state : restore
target : /tmp/testdb.sql
when : postgres_ensure_testdb | default(False)