From 5aa9869845c1823e25902fcb71c5ba46d72bd5f5 Mon Sep 17 00:00:00 2001 From: Jakub Czajka Date: Sat, 2 Dec 2023 17:15:06 +0100 Subject: [PATCH] [config] Configure automatic deployment. --- config.git/deploy.yaml | 20 ++++++++++++++++++++ config.git/hooks/post-receive | 13 +++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 config.git/deploy.yaml create mode 100755 config.git/hooks/post-receive 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 -- 2.39.5