@ -3,22 +3,22 @@
- name : Check role exists
- name : Check role exists
become : yes
become : yes
become_user : postgres
become_user : postgres
shell : "/usr/bin/psql -Atc \"SELECT count(rolname) FROM pg_roles where rolname='replicator'\""
shell : "/usr/bin/psql -Atc \"SELECT count(rolname) FROM pg_roles where rolname='replicator'\"" # noqa command-instead-of-shell
register : role_check
register : role_check
ignore_errors : yes
ignore_errors : yes # noqa ignore-errors no-changed-when
- name : Create role if necessary
- name : Create role if necessary
become : yes
become : yes
become_user : postgres
become_user : postgres
shell : "/usr/bin/psql -c 'CREATE ROLE replicator WITH REPLICATION LOGIN;'"
shell : "/usr/bin/psql -c 'CREATE ROLE replicator WITH REPLICATION LOGIN;'"
when : role_check.stdout == "0"
when : role_check.stdout == "0"
ignore_errors : yes
ignore_errors : yes # noqa ignore-errors
- name : Change password with scram-sha-256! for replicator and set password
- name : Change password with scram-sha-256! for replicator and set password
become : yes
become : yes
become_user : postgres
become_user : postgres
shell : "/usr/bin/psql -c \"set password_encryption = 'scram-sha-256';ALTER ROLE replicator WITH PASSWORD '{{ postgres_replicator_user_password }}';\""
shell : "/usr/bin/psql -c \"set password_encryption = 'scram-sha-256';ALTER ROLE replicator WITH PASSWORD '{{ postgres_replicator_user_password }}';\""
ignore_errors : yes
ignore_errors : yes # noqa ignore-errors no-changed-when
- name : Setup pg_hba.conf for replicator user
- name : Setup pg_hba.conf for replicator user
lineinfile:
lineinfile:
@ -82,13 +82,13 @@
state : present
state : present
register : nfsshare_archive_check
register : nfsshare_archive_check
- name : Restart nfs-server if necessary
- name : Restart nfs-server if necessary # noqa no-handler
service:
service:
name : nfs-kernel-server
name : nfs-kernel-server
state : restarted
state : restarted
when : nfsshare_archive_check.changed
when : nfsshare_archive_check.changed
- name : Restart postgres if necessary
- name : Restart postgres if necessary # noqa no-handler
service:
service:
name : postgresql
name : postgresql
state : restarted
state : restarted
@ -104,39 +104,39 @@
become : yes
become : yes
become_user : postgres
become_user : postgres
shell : "/usr/bin/psql template1 -c \"create extension if not exists pgcrypto;\""
shell : "/usr/bin/psql template1 -c \"create extension if not exists pgcrypto;\""
ignore_errors : yes
ignore_errors : yes # noqa ignore-errors no-changed-when
- name : Check database replication_cron exists
- name : Check database replication_cron exists
become : yes
become : yes
become_user : postgres
become_user : postgres
shell : "/usr/bin/psql -Atc \"SELECT count(*) FROM pg_database WHERE datname = 'replication_cron'\""
shell : "/usr/bin/psql -Atc \"SELECT count(*) FROM pg_database WHERE datname = 'replication_cron'\""
register : database_replication_check
register : database_replication_check
ignore_errors : yes
ignore_errors : yes # noqa ignore-errors no-changed-when
- name : Create replication_cron update database
- name : Create replication_cron update database
become : yes
become : yes
become_user : postgres
become_user : postgres
shell : "/usr/bin/psql -c \"CREATE DATABASE replication_cron;\""
shell : "/usr/bin/psql -c \"CREATE DATABASE replication_cron;\""
when : database_replication_check.stdout == "0"
when : database_replication_check.stdout == "0"
ignore_errors : yes
ignore_errors : yes # noqa ignore-errors no-changed-when
- name : Create replication update schema
- name : Create replication update schema
become : yes
become : yes
become_user : postgres
become_user : postgres
shell : "/usr/bin/psql replication_cron -c \"CREATE SCHEMA IF NOT EXISTS replication_cron;\""
shell : "/usr/bin/psql replication_cron -c \"CREATE SCHEMA IF NOT EXISTS replication_cron;\""
ignore_errors : yes
ignore_errors : yes # noqa ignore-errors no-changed-when
- name : Create replication update table
- name : Create replication update table
become : yes
become : yes
become_user : postgres
become_user : postgres
shell : "/usr/bin/psql replication_cron -c \"CREATE TABLE IF NOT EXISTS replication_cron.replication_cron (dt timestamp);\""
shell : "/usr/bin/psql replication_cron -c \"CREATE TABLE IF NOT EXISTS replication_cron.replication_cron (dt timestamp);\""
ignore_errors : yes
ignore_errors : yes # noqa ignore-errors no-changed-when
- name : Create dummy update data
- name : Create dummy update data
become : yes
become : yes
become_user : postgres
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);\""
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
ignore_errors : yes # noqa ignore-errors no-changed-when
- name : Ensure a cron runs every 5 minutes and update replication check table"
- name : Ensure a cron runs every 5 minutes and update replication check table"
ansible.builtin.cron:
ansible.builtin.cron:
@ -149,11 +149,11 @@
become_user : postgres
become_user : postgres
shell : "/usr/bin/psql -Atc \"select count(*) from pg_replication_slots where slot_name='pgstandby1'\""
shell : "/usr/bin/psql -Atc \"select count(*) from pg_replication_slots where slot_name='pgstandby1'\""
register : replication_slot_check
register : replication_slot_check
ignore_errors : yes
ignore_errors : yes # noqa ignore-errors no-changed-when
- name : Create replication-slot
- name : Create replication-slot
become : yes
become : yes
become_user : postgres
become_user : postgres
shell : "/usr/bin/psql -Atc \"SELECT pg_create_physical_replication_slot('pgstandby1');\""
shell : "/usr/bin/psql -Atc \"SELECT pg_create_physical_replication_slot('pgstandby1');\""
ignore_errors : yes
ignore_errors : yes # noqa ignore-errors
when : replication_slot_check.stdout == "0"
when : replication_slot_check.stdout == "0"