commit aca231c728ecb85a319ac03dc6b34d3e050f3893 Author: phil Date: Sat Nov 4 13:07:10 2023 +0100 Init diff --git a/README.md b/README.md new file mode 100644 index 0000000..878fd78 --- /dev/null +++ b/README.md @@ -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`. diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..52139f6 --- /dev/null +++ b/defaults/main.yml @@ -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 diff --git a/files/systemd/override.conf b/files/systemd/override.conf new file mode 100644 index 0000000..bf45b90 --- /dev/null +++ b/files/systemd/override.conf @@ -0,0 +1,4 @@ +# Ansible managed + +[Service] +Restart=always diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..40eafb2 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,9 @@ +--- +- name: Reload systemd + ansible.builtin.systemd: + daemon_reload: true + +- name: Restart postgresql + ansible.builtin.service: + name: postgresql + state: restarted diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..ba50c56 --- /dev/null +++ b/meta/main.yml @@ -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 diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..42c38a1 --- /dev/null +++ b/tasks/main.yml @@ -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 diff --git a/templates/autopostgresqlbackup.j2 b/templates/autopostgresqlbackup.j2 new file mode 100644 index 0000000..e34b612 --- /dev/null +++ b/templates/autopostgresqlbackup.j2 @@ -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 %} diff --git a/templates/autopostgresqlbackup_post_script.j2 b/templates/autopostgresqlbackup_post_script.j2 new file mode 100644 index 0000000..ad4d4d4 --- /dev/null +++ b/templates/autopostgresqlbackup_post_script.j2 @@ -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