This commit is contained in:
phil 2023-11-04 13:07:10 +01:00
commit aca231c728
8 changed files with 86 additions and 0 deletions

4
README.md Normal file
View file

@ -0,0 +1,4 @@
Ansible role to configure PostgreSQL
===================================
This is a helper role to run some tasks that are not part of `geerlingguy.postgresql`.

11
defaults/main.yml Normal file
View file

@ -0,0 +1,11 @@
---
autopostgresqlbackup_delete_backups_after_days: 8
autopostgresqlbackup_config:
dbhost: localhost
backupdir: /var/lib/autopostgresqlbackup
mailaddr: root
sepdir: "yes"
comp: bzip2
latest: "no"
postbackup: /usr/local/bin/autopostgresqlbackup_post_script

View file

@ -0,0 +1,4 @@
# Ansible managed
[Service]
Restart=always

9
handlers/main.yml Normal file
View file

@ -0,0 +1,9 @@
---
- name: Reload systemd
ansible.builtin.systemd:
daemon_reload: true
- name: Restart postgresql
ansible.builtin.service:
name: postgresql
state: restarted

10
meta/main.yml Normal file
View file

@ -0,0 +1,10 @@
galaxy_info:
author: Sense.Lab admins
description: Configure PostgreSQL
company: Sense.Lab e.V.
license: GPLv3
min_ansible_version: "2.14"
platforms:
- name: Debian
versions:
- bookworm

26
tasks/main.yml Normal file
View file

@ -0,0 +1,26 @@
---
- name: Install autopostgresqlbackup
ansible.builtin.apt:
pkg: autopostgresqlbackup
update_cache: true
- name: Copy autopostgresqlbackup configuration
ansible.builtin.template:
src: autopostgresqlbackup.j2
dest: /etc/default/autopostgresqlbackup
mode: "0644"
- name: Copy autopostgresqlbackup postbackup script
ansible.builtin.template:
src: autopostgresqlbackup_post_script.j2
dest: "{{ autopostgresqlbackup_config.postbackup }}"
mode: "0755"
- name: Copy systemd override
ansible.builtin.copy:
src: systemd/override.conf
dest: /etc/systemd/system/postgresql@.service.d/
mode: "0644"
notify:
- Reload systemd
- Restart postgresql

View file

@ -0,0 +1,9 @@
# {{ ansible_managed }}
{% for key, value in autopostgresqlbackup_config.items() %}
{% if value is number %}
{{ key | upper }}={{ value }}
{% else %}
{{ key | upper }}="{{ value }}"
{% endif %}
{% endfor %}

View file

@ -0,0 +1,13 @@
### {{ ansible_managed }}
source /etc/default/autopostgresqlbackup
# available variables:
# strings, i.e. character sequences
echo "$BACKUPDIR"
[ -z "$BACKUPDIR" ] && echo >&2 "Invalid / unknown BACKUPDIR" && exit 1
# Loeschen der alten Backups
find "${BACKUPDIR}/monthly" "${BACKUPDIR}/weekly" "${BACKUPDIR}/daily" -type f -mtime +{{ autopostgresqlbackup_delete_backups_after_days }} -delete