@ -1,13 +1,12 @@
---
- name : Check role exists
- name : Check role exists # noqa no-changed-when
become : true
become_user : postgres
ansible.builtin.shell : '/usr/bin/psql -Atc "SELECT count(rolname) FROM pg_roles where rolname=' 'replicator' '"' # noqa command-instead-of-shell
register : role_check
ignore_errors : true # noqa ignore-errors no-changed-when
- name : Create role if necessary
- name : Create role if necessary # noqa no-changed-when
become : true
become_user : postgres
ansible.builtin.shell : "/usr/bin/psql -c 'CREATE ROLE replicator WITH REPLICATION LOGIN;'"
@ -15,7 +14,7 @@
register : cmd_ret
changed_when : cmd_ret.rc != 0
- name : Change password with scram-sha-256! for replicator and set password
- name : Change password with scram-sha-256! for replicator and set password # noqa no-changed-when
become : true
become_user : postgres
ansible.builtin.shell : >-
@ -123,39 +122,34 @@
wal_keep_size.changed or
ansible_facts.services["postgresql.service"].state != "active"
- name : Create extension pgcrypto for template1
- name : Create extension pgcrypto for template1 # noqa no-changed-when
become : true
become_user : postgres
ansible.builtin.shell : '/usr/bin/psql template1 -c "create extension if not exists pgcrypto;"'
ignore_errors : true # noqa ignore-errors no-changed-when
- name : Check database replication_cron exists
- name : Check database replication_cron exists # noqa no-changed-when
become : true
become_user : postgres
ansible.builtin.shell : '/usr/bin/psql -Atc "SELECT count(*) FROM pg_database WHERE datname = ' 'replication_cron' '"'
register : database_replication_check
ignore_errors : true # noqa ignore-errors no-changed-when
- name : Create replication_cron update database
- name : Create replication_cron update database # noqa no-changed-when
become : true
become_user : postgres
ansible.builtin.shell : '/usr/bin/psql -c "CREATE DATABASE replication_cron;"'
when : database_replication_check.stdout == "0"
ignore_errors : true # noqa ignore-errors no-changed-when
- name : Create replication update schema
- name : Create replication update schema # noqa no-changed-when
become : true
become_user : postgres
ansible.builtin.shell : '/usr/bin/psql replication_cron -c "CREATE SCHEMA IF NOT EXISTS replication_cron;"'
ignore_errors : true # noqa ignore-errors no-changed-when
- name : Create replication update table
- name : Create replication update table # noqa no-changed-when
become : true
become_user : postgres
ansible.builtin.shell : '/usr/bin/psql replication_cron -c "CREATE TABLE IF NOT EXISTS replication_cron.replication_cron (dt timestamp);"'
ignore_errors : true # noqa ignore-errors no-changed-when
- name : Create dummy update data
- name : Create dummy update data # noqa command-instead-of-shell
become : true
become_user : postgres
ansible.builtin.shell : >-
@ -163,11 +157,9 @@
"INSERT INTO replication_cron.replication_cron
SELECT NOW()
WHERE NOT EXISTS
(SELECT 1
FROM replication_cron.replication_cron)"
(SELECT 1 FROM replication_cron.replication_cron)"
register : cmd_ret
changed_when : cmd_ret.rc != 0
ignore_errors : true # noqa command-instead-of-shell
- name : Ensure a cron runs every 5 minutes and update replication check table"
ansible.builtin.cron:
@ -175,21 +167,19 @@
minute : "*/5"
job : su - postgres -c "/usr/bin/psql replication_cron -c \"UPDATE replication_cron.replication_cron SET dt=now();\""
- name : Check replication slot exists
- name : Check replication slot exists # noqa no-changed-when
become : true
become_user : postgres
ansible.builtin.shell : '/usr/bin/psql -Atc "select count(*) from pg_replication_slots where slot_name=' 'pgstandby1' '"'
register : replication_slot_check
ignore_errors : true # noqa ignore-errors no-changed-when
- name : Create replication-slot
- name : Create replication-slot # noqa no-changed-when
become : true
become_user : postgres
ansible.builtin.shell : '/usr/bin/psql -Atc "SELECT pg_create_physical_replication_slot(' 'pgstandby1' ');"'
when : replication_slot_check.stdout == "0"
register : cmd_ret
changed_when : cmd_ret.rc != 0
ignore_errors : true # noqa command-instead-of-shell
# only needed in case of install from scratch
- name : "Ensure test db stuff"