]> git.ekhem.eu.org Git - metadata.git/commitdiff
[config] Configure automatic deployment.
authorJakub Czajka <jakub@ekhem.eu.org>
Sat, 2 Dec 2023 16:15:06 +0000 (17:15 +0100)
committerJakub Czajka <jczajka@google.com>
Sun, 24 Dec 2023 18:45:06 +0000 (19:45 +0100)
config.git/deploy.yaml [new file with mode: 0644]
config.git/hooks/post-receive [new file with mode: 0755]

diff --git a/config.git/deploy.yaml b/config.git/deploy.yaml
new file mode 100644 (file)
index 0000000..83df766
--- /dev/null
@@ -0,0 +1,20 @@
+# 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 }}/config.git"
+  tasks:
+    - name: Checkout environment to /etc
+      command: /usr/bin/git --work-tree=/etc --git-dir={{ repo }} \
+        checkout main --force environment
+      become: true
+    - name: Create facts.d directory
+      file:
+        path: /etc/ansible/facts.d
+        state: directory
+      become: true
+    - name: Export environment as ansible facts in the .ini format
+      shell: sed --expression 's/export\s//g ; s/\"//g ; 1s/^.*$/[vars]/' \
+        /etc/environment > /etc/ansible/facts.d/env.fact
+      become: true
diff --git a/config.git/hooks/post-receive b/config.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