2026-06-29 09:02:59 +02:00
|
|
|
---
|
|
|
|
|
- name: Postgres Servers
|
|
|
|
|
hosts: postgres
|
|
|
|
|
pre_tasks:
|
|
|
|
|
- name: Postgres Repo
|
|
|
|
|
ansible.builtin.dnf:
|
|
|
|
|
name: 'https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm'
|
|
|
|
|
state: present
|
2026-07-17 09:40:12 +02:00
|
|
|
disable_gpg_check: true
|
2026-06-29 09:02:59 +02:00
|
|
|
|
2026-07-02 11:36:52 +02:00
|
|
|
- name: Postgres RPMs
|
|
|
|
|
ansible.builtin.dnf:
|
|
|
|
|
name:
|
|
|
|
|
- postgresql18-server
|
|
|
|
|
- postgresql18-contrib
|
|
|
|
|
state: latest
|
|
|
|
|
|
2026-06-29 09:02:59 +02:00
|
|
|
tasks:
|
2026-07-17 09:40:12 +02:00
|
|
|
- name: Create Database Logical Volume
|
|
|
|
|
community.general.lvol:
|
|
|
|
|
vg: data
|
|
|
|
|
lv: pgdata
|
|
|
|
|
size: 32G
|
|
|
|
|
|
|
|
|
|
- name: Create Database Filesystem
|
|
|
|
|
community.general.filesystem:
|
|
|
|
|
fstype: xfs
|
|
|
|
|
dev: /dev/data/pgdata
|
|
|
|
|
|
|
|
|
|
- name: Mount filesystems
|
|
|
|
|
ansible.posix.mount:
|
|
|
|
|
path: '/var/lib/pgsql'
|
|
|
|
|
src: '/dev/data/pgdata'
|
|
|
|
|
opts: 'noatime'
|
|
|
|
|
state: mounted
|
|
|
|
|
fstype: "xfs"
|
|
|
|
|
|
|
|
|
|
- name: Open Firewall port
|
|
|
|
|
firewalld:
|
|
|
|
|
# service: docker-registry
|
|
|
|
|
service: postgresql
|
|
|
|
|
permanent: true
|
|
|
|
|
state: enabled
|
|
|
|
|
immediate: yes
|
|
|
|
|
when: ansible_facts['os_family'] == "RedHat"
|
|
|
|
|
|
2026-07-02 11:36:52 +02:00
|
|
|
- name: PG Backup directory
|
|
|
|
|
file:
|
|
|
|
|
path: '/var/backups/postgres'
|
|
|
|
|
state: directory
|
|
|
|
|
mode: '0775'
|
|
|
|
|
owner: postgres
|
|
|
|
|
group: postgres
|
|
|
|
|
|
2026-06-29 09:02:59 +02:00
|
|
|
- name: Backup script
|
|
|
|
|
copy:
|
|
|
|
|
src: 'bin/pg-backup'
|
|
|
|
|
dest: '/usr/local/bin/pg-backup'
|
|
|
|
|
mode: '0755'
|
|
|
|
|
|
|
|
|
|
- name: Setup Postgres backup cron job
|
|
|
|
|
ansible.builtin.cron:
|
2026-07-10 16:45:41 +02:00
|
|
|
name: "pg-backup"
|
2026-06-29 09:02:59 +02:00
|
|
|
minute: 30
|
|
|
|
|
hour: 23
|
|
|
|
|
job: /usr/local/bin/pg-backup
|