--- /dev/null
+# Copyright (c) 2023 Jakub Czajka <jakub@ekhem.eu.org>
+# License: GPL-3.0 or later.
+
+git ALL=(ALL) NOPASSWD: /usr/bin/ansible-playbook
========
Metadata files (descriptions, hooks etc.) for the other git repositories.
+
+Install
+-------
+
+Copy the `post-receive` hook to `metadata.git/hooks` in order for the repository
+to automatically update other repositories. It copies files from this repository
+to `/srv/git` after each commit.
--- /dev/null
+# Copyright (c) 2023 Jakub Czajka <jakub@ekhem.eu.org>
+# License: GPL-3.0 or later.
+
+- hosts: servers
+ vars:
+ dest: "{{ ansible_local.env.vars.git_home_dir }}"
+ repo: "{{ ansible_local.env.vars.git_home_dir }}/metadata.git"
+ tasks:
+ - name: Checkout metadata's configuration files to the destination directory
+ command: /usr/bin/git --work-tree={{ dest }} --git-dir={{ repo }} \
+ checkout main --force
+ become: true
+ - name: Move 90-git to /etc/sudoers.d
+ command: /usr/bin/mv {{ dest }}/90-git /etc/sudoers.d
+ become: true
+ - name: Set ownership and permissions for /etc/sudoers.d/90-git
+ file:
+ path: /etc/sudoers.d/90-git
+ mode: 0440
+ owner: root
+ group: root
+ become: true
+
+ - name: Install ansible
+ package:
+ name:
+ - ansible
+ state: latest
+ become: true
+ - find:
+ paths: "{{ dest }}"
+ recurse: true
+ patterns: post-receive
+ register: post_receive_scripts
+ - name: Make all post-receive scripts executable and set ownership
+ file:
+ path: "{{ item.path }}"
+ mode: 0744
+ owner: git
+ group: git
+ become: true
+ with_items: "{{ post_receive_scripts.files }}"
--- /dev/null
+#!/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