From bd041c8dc7544ee1ff5ba76b890ab1c1820f412c Mon Sep 17 00:00:00 2001
From: Benjamin Graillot <graillot@crans.org>
Date: Thu, 29 Apr 2021 14:38:56 +0200
Subject: [PATCH] [home] Use new home script

---
 plays/home.yml                         |  1 +
 roles/home/tasks/main.yml              |  5 +++--
 roles/home/templates/cron.d/home.j2    |  2 +-
 roles/home/templates/home/config.py.j2 | 10 ----------
 roles/home/templates/home/home.json.j2 | 11 +++++++++++
 5 files changed, 16 insertions(+), 13 deletions(-)
 delete mode 100644 roles/home/templates/home/config.py.j2
 create mode 100644 roles/home/templates/home/home.json.j2

diff --git a/plays/home.yml b/plays/home.yml
index 4104c91e..866016c6 100755
--- a/plays/home.yml
+++ b/plays/home.yml
@@ -7,5 +7,6 @@
       ldap_password: "{{ vault.ldap_home_password }}"
       binddn: cn=home,ou=service-users,dc=crans,dc=org
       rootdn: cn=Utilisateurs,dc=crans,dc=org
+      borg_key: "{{ vault.borgbackup_passwd }}"
   roles:
     - home
diff --git a/roles/home/tasks/main.yml b/roles/home/tasks/main.yml
index 10b1ebc5..e20d0ea4 100644
--- a/roles/home/tasks/main.yml
+++ b/roles/home/tasks/main.yml
@@ -4,6 +4,7 @@
     update_cache: true
     install_recommends: false
     name:
+      - python3-jinja2
       - python3-ldap
   register: apt_result
   retries: 3
@@ -34,8 +35,8 @@
 
 - name: Deploy home config
   template:
-    src: home/config.py.j2
-    dest: /var/local/home/config.py
+    src: home/home.json.j2
+    dest: /var/local/home/home.json
     mode: 0600
     owner: root
     group: root
diff --git a/roles/home/templates/cron.d/home.j2 b/roles/home/templates/cron.d/home.j2
index f26e2e46..b64d9a87 100644
--- a/roles/home/templates/cron.d/home.j2
+++ b/roles/home/templates/cron.d/home.j2
@@ -1,2 +1,2 @@
 {{ ansible_header | comment }}
-* * * * * root /usr/bin/python3 /var/local/home/main.py
+* * * * * root /usr/bin/python3 /var/local/home/home.py
diff --git a/roles/home/templates/home/config.py.j2 b/roles/home/templates/home/config.py.j2
deleted file mode 100644
index 7d3d2233..00000000
--- a/roles/home/templates/home/config.py.j2
+++ /dev/null
@@ -1,10 +0,0 @@
-{{ ansible_header | comment }}
-
-ldap_server = '{{ home.ldap_server }}'
-binddn = '{{ home.binddn }}'
-password = '{{ home.ldap_password }}'
-rootdn = '{{ home.rootdn }}'
-home_dir = '/pool/home'
-mail_dir = '/pool/mail'
-home_quota = '/usr/sbin/zfs set userquota@{user}=30G pool/home'
-mail_quota = '/usr/sbin/zfs set userquota@{user}=10G pool/mail'
diff --git a/roles/home/templates/home/home.json.j2 b/roles/home/templates/home/home.json.j2
new file mode 100644
index 00000000..ada269e1
--- /dev/null
+++ b/roles/home/templates/home/home.json.j2
@@ -0,0 +1,11 @@
+{
+	"ldap_server": "{{ home.ldap_server }}"
+	"binddn": "{{ home.binddn }}"
+	"password": "{{ home.ldap_password }}"
+	"rootdn": "{{ home.rootdn }}"
+	"home_dir": "/pool/home"
+	"mail_dir": "/pool/mail"
+	"home_quota": "/usr/sbin/zfs set userquota@{user}=30G pool/home"
+	"mail_quota": "/usr/sbin/zfs set userquota@{user}=10G pool/mail"
+	"borg_key": "{{ home.borg_key }}"
+}
-- 
GitLab