From: Jakub Czajka Date: Thu, 30 Nov 2023 20:05:31 +0000 (+0100) Subject: [cron] Configure automatic deployment. X-Git-Url: https://git.ekhem.eu.org/?a=commitdiff_plain;h=ab7fe2ddf37f1b54de9a1b9d8a1870615fe5f835;p=metadata.git [cron] Configure automatic deployment. --- diff --git a/cron.git/deploy.yaml b/cron.git/deploy.yaml new file mode 100644 index 0000000..5ce49a7 --- /dev/null +++ b/cron.git/deploy.yaml @@ -0,0 +1,23 @@ +# Copyright (c) 2023 Jakub Czajka +# 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 index 0000000..c64a663 --- /dev/null +++ b/cron.git/hooks/post-receive @@ -0,0 +1,13 @@ +#!/bin/sh +# Copyright (c) 2023 Jakub Czajka +# 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