]> git.ekhem.eu.org Git - metadata.git/commitdiff
[cron] Configure automatic deployment.
authorJakub Czajka <jakub@ekhem.eu.org>
Thu, 30 Nov 2023 20:05:31 +0000 (21:05 +0100)
committerJakub Czajka <jczajka@google.com>
Sun, 24 Dec 2023 18:45:06 +0000 (19:45 +0100)
cron.git/deploy.yaml [new file with mode: 0644]
cron.git/hooks/post-receive [new file with mode: 0755]

diff --git a/cron.git/deploy.yaml b/cron.git/deploy.yaml
new file mode 100644 (file)
index 0000000..5ce49a7
--- /dev/null
@@ -0,0 +1,23 @@
+# Copyright (c) 2023 Jakub Czajka <jakub@ekhem.eu.org>
+# License: GPL-3.0 or later.
+
+- hosts: servers
+  vars:
+    repo: "{{ ansible_local.env.vars.git_home_dir }}/cron.git"
+  tasks:
+    - name: Checkout systemd services and timers
+      command: /usr/bin/git --work-tree=/etc/systemd/system \
+        --git-dir={{ repo }} checkout main --force *.service *.timer
+      become: true
+    - find:
+        paths: /etc/systemd/system
+        file_type: file
+        patterns: "*.timer"
+      register: timers
+    - name: Enable all timers
+      service:
+        name: "{{ item.path }}"
+        enabled: true
+        daemon_reload: true
+      become: true
+      with_items: "{{ timers.files }}"
diff --git a/cron.git/hooks/post-receive b/cron.git/hooks/post-receive
new file mode 100755 (executable)
index 0000000..c64a663
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/sh
+# Copyright (c) 2023 Jakub Czajka <jakub@ekhem.eu.org>
+# License: GPL-3.0 or later.
+
+while read old_revision new_revision branch
+do
+    if [ "${branch}" != "refs/heads/main" ]
+    then
+        echo "${branch} is not the main branch so not deploying."
+        exit 0
+    fi
+    sudo /usr/bin/ansible-playbook --connection=local deploy.yaml
+done