From 3fb7ccd90e2d82070f8be609002272378b7cef91 Mon Sep 17 00:00:00 2001
From: Lars Beckers <lars.beckers@rwth-aachen.de>
Date: Sat, 14 Jul 2018 14:54:52 +0200
Subject: [PATCH] postgres: allow for disabling frequently snapshots

---
 postgres/defaults/main.yml                    |  3 ++
 postgres/tasks/main.yml                       | 41 +++++++++++++------
 .../{files/crontab => templates/crontab.j2}   |  2 +
 .../rsnapshot.conf.j2}                        |  2 +
 4 files changed, 35 insertions(+), 13 deletions(-)
 create mode 100644 postgres/defaults/main.yml
 rename postgres/{files/crontab => templates/crontab.j2} (82%)
 rename postgres/{files/rsnapshot.conf => templates/rsnapshot.conf.j2} (99%)

diff --git a/postgres/defaults/main.yml b/postgres/defaults/main.yml
new file mode 100644
index 0000000..496c92b
--- /dev/null
+++ b/postgres/defaults/main.yml
@@ -0,0 +1,3 @@
+---
+
+postgres_enable_frequently: True
diff --git a/postgres/tasks/main.yml b/postgres/tasks/main.yml
index ee8897e..d46b069 100644
--- a/postgres/tasks/main.yml
+++ b/postgres/tasks/main.yml
@@ -1,51 +1,66 @@
 ---
-# file: roles/postgres/tasks/main.yml
 
 - name: ensure postgres packages are installed
-  apt: name={{ item }} state=latest
+  apt:
+    name: "{{ item }}"
+    state: present
   with_items:
     - postgresql
     - python-psycopg2
     - python3-psycopg2
     - libpq-dev
   tags:
-    - packages
     - postgres
 
 - name: ensure postgres is started
-  service: name=postgresql state=started enabled=yes
+  service:
+    name: postgresql
+    state: started
+    enabled: yes
   tags:
-    - service
     - postgres
 
 - name: ensure we have rsnapshot
-  apt: name=rsnapshot state=latest
+  apt:
+    name: rsnapshot
+    state: present
   tags:
-    - packages
     - postgres
     - rsnapshot
     - backup
 
 - name: ensure we have our postgres backup script
-  copy: src=pgbackup.sh dest=/usr/local/bin/ owner=root group=root mode=0755
+  copy:
+    src: pgbackup.sh
+    dest: /usr/local/bin/
+    owner: root
+    group: root
+    mode: 0755
   tags:
     - postgres
     - rsnapshot
     - backup
 
 - name: ensure we have our rsnapshot config
-  copy: src=rsnapshot.conf dest=/etc/ owner=root group=root mode=0644
+  template:
+    src: rsnapshot.conf.j2
+    dest: /etc/
+    owner: root
+    group: root
+    mode: 0644
   tags:
     - postgres
     - rsnapshot
     - backup
-    - config
 
 - name: ensure rsnapshot is running regularly
-  copy: src=crontab dest=/etc/cron.d/postgres-snapshot owner=root group=root mode=0644
+  template:
+    src: crontab.j2
+    dest: /etc/cron.d/postgres-snapshot
+    owner: root
+    group: root
+    mode: 0644
   tags:
     - postgres
     - rsnapshot
     - backup
-    - cron
-    - config
diff --git a/postgres/files/crontab b/postgres/templates/crontab.j2
similarity index 82%
rename from postgres/files/crontab
rename to postgres/templates/crontab.j2
index 9cc887a..1d0e2f5 100644
--- a/postgres/files/crontab
+++ b/postgres/templates/crontab.j2
@@ -1,4 +1,6 @@
+{% if postgres_enable_frequently %}
 5,20,35,50 * * * * root /usr/bin/rsnapshot frequently
+{% endif %}
 3 * * * * root /usr/bin/rsnapshot hourly
 51 23 * * * root /usr/bin/rsnapshot daily
 41 23 * * 6 root /usr/bin/rsnapshot weekly
diff --git a/postgres/files/rsnapshot.conf b/postgres/templates/rsnapshot.conf.j2
similarity index 99%
rename from postgres/files/rsnapshot.conf
rename to postgres/templates/rsnapshot.conf.j2
index 0020529..97657c5 100644
--- a/postgres/files/rsnapshot.conf
+++ b/postgres/templates/rsnapshot.conf.j2
@@ -90,7 +90,9 @@ cmd_logger	/usr/bin/logger
 # e.g. alpha, beta, gamma, etc.         #
 #########################################
 
+{% if postgres_enable_frequently %}
 retain	frequently	4
+{% endif %}
 retain	hourly	6
 retain	daily	7
 retain	weekly	4
-- 
GitLab