From: Jakub Czajka Date: Sat, 2 Dec 2023 16:15:06 +0000 (+0100) Subject: [config] Configure automatic deployment. X-Git-Url: https://git.ekhem.eu.org/?a=commitdiff_plain;h=5aa9869845c1823e25902fcb71c5ba46d72bd5f5;p=metadata.git [config] Configure automatic deployment. --- diff --git a/config.git/deploy.yaml b/config.git/deploy.yaml new file mode 100644 index 0000000..83df766 --- /dev/null +++ b/config.git/deploy.yaml @@ -0,0 +1,20 @@ +# Copyright (c) 2023 Jakub Czajka +# 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 index 0000000..c64a663 --- /dev/null +++ b/config.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