From 26449924b80c46d4a6aff0febaf774f3d40bbfcc Mon Sep 17 00:00:00 2001 From: Mark Hoekveen Date: Wed, 7 Oct 2026 18:23:28 +0200 Subject: [PATCH] shared gitea checkouts --- group_vars/all.yml | 2 ++ host_vars/akatosh.yml | 2 +- playbook.yml | 1 + tasks/gitea_checkout.yml | 60 ++++++++++++++++++++++++++++++++++++++++ tasks/scripts.yml | 19 +++---------- tasks/stroopwafel.yml | 29 ++++++++----------- 6 files changed, 79 insertions(+), 34 deletions(-) create mode 100644 group_vars/all.yml create mode 100644 tasks/gitea_checkout.yml diff --git a/group_vars/all.yml b/group_vars/all.yml new file mode 100644 index 0000000..6c6f109 --- /dev/null +++ b/group_vars/all.yml @@ -0,0 +1,2 @@ +gitea_ssh: gitea@git.hoekveen.net +gitea_https: https://git.hoekveen.net diff --git a/host_vars/akatosh.yml b/host_vars/akatosh.yml index 81fbaa4..c946602 100644 --- a/host_vars/akatosh.yml +++ b/host_vars/akatosh.yml @@ -37,7 +37,7 @@ fail2ban_ignoreip: - home.hoekveen.net stroopwafel_dir: /opt/stroopwafel -stroopwafel_repo: gitea@git.hoekveen.net:mark/stroopwafel.git +stroopwafel_repo: mark/stroopwafel stroopwafel_version: master backup_dump_dir: /var/backups/aurbis diff --git a/playbook.yml b/playbook.yml index 5f5817d..1473c80 100644 --- a/playbook.yml +++ b/playbook.yml @@ -67,6 +67,7 @@ remote_user: nerevar tasks: - import_tasks: tasks/scripts.yml + tags: scripts - name: Setup zsh hosts: debian become: true diff --git a/tasks/gitea_checkout.yml b/tasks/gitea_checkout.yml new file mode 100644 index 0000000..20ad2ae --- /dev/null +++ b/tasks/gitea_checkout.yml @@ -0,0 +1,60 @@ +# Shared checkout of a gitea repo: root seeds and fast-forwards it over anonymous +# https, aurbis members push and pull over ssh with their own gitea key. +- name: Create {{ checkout_repo }} directory + file: + path: "{{ checkout_dest }}" + state: directory + owner: root + group: aurbis + mode: "02775" +- name: Seed {{ checkout_repo }} + ansible.builtin.git: + repo: "{{ gitea_https }}/{{ checkout_repo }}.git" + dest: "{{ checkout_dest }}" + version: "{{ checkout_version | default('master') }}" + update: false + force: false +- name: Point {{ checkout_repo }} origin at git-over-ssh + community.general.git_config: + name: remote.origin.url + scope: local + repo: "{{ checkout_dest }}" + value: "{{ gitea_ssh }}:{{ checkout_repo }}.git" +- name: Have git keep {{ checkout_repo }} group-writable + community.general.git_config: + name: core.sharedRepository + scope: local + repo: "{{ checkout_dest }}" + value: group +- name: Add {{ checkout_repo }} to safe.directory + community.general.git_config: + name: safe.directory + scope: system + add_mode: add + value: "{{ checkout_dest }}" +# ff-only, so unpushed commits or conflicting edits on the host fail the run instead of being lost. +- name: Fast-forward {{ checkout_repo }} + ansible.builtin.shell: + chdir: "{{ checkout_dest }}" + cmd: | + set -e + umask 002 + before=$(git rev-parse HEAD) + git fetch -q {{ gitea_https }}/{{ checkout_repo }}.git +refs/heads/{{ checkout_version | default('master') }}:refs/remotes/origin/{{ checkout_version | default('master') }} + git merge -q --ff-only origin/{{ checkout_version | default('master') }} + [ "$before" = "$(git rev-parse HEAD)" ] || echo updated + register: checkout_pull + changed_when: "'updated' in checkout_pull.stdout" + when: checkout_update | default(true) +- name: Give aurbis write access to {{ checkout_repo }} + file: + path: "{{ checkout_dest }}" + state: directory + recurse: true + group: aurbis + mode: g+rwX +- name: Make {{ checkout_repo }} directories hand their group to new files + ansible.builtin.command: + cmd: "find {{ checkout_dest }} -type d ! -perm -g+s -print -exec chmod g+s {} +" + register: checkout_setgid + changed_when: checkout_setgid.stdout != "" diff --git a/tasks/scripts.yml b/tasks/scripts.yml index 19f3cf0..fc8aa54 100644 --- a/tasks/scripts.yml +++ b/tasks/scripts.yml @@ -1,15 +1,4 @@ -- name: Git clone - ansible.builtin.git: - repo: https://git.hoekveen.net/mark/scripts.git - dest: /opt/scripts - force: true -- name: Set permissions and ownership for scripts folder - file: - path: /opt/scripts - state: directory - recurse: true - group: aurbis - mode: "0775" -- name: Add scripts directory to safe.directory - ansible.builtin.command: - cmd: git config --system --add safe.directory /opt/scripts +- import_tasks: gitea_checkout.yml + vars: + checkout_repo: mark/scripts + checkout_dest: /opt/scripts diff --git a/tasks/stroopwafel.yml b/tasks/stroopwafel.yml index 0712b50..40011d9 100644 --- a/tasks/stroopwafel.yml +++ b/tasks/stroopwafel.yml @@ -1,31 +1,19 @@ -# Pulling needs to have git access; root does not. - name: Include stroopwafel vault include_vars: dir: stroopwafel files_matching: vault.yml -- name: Create stroopwafel directory - file: - path: "{{ stroopwafel_dir }}" - state: directory - owner: root - group: "{{ service_group | default('aurbis') }}" - mode: "0775" -- name: Check out stroopwafel source - ansible.builtin.git: - repo: "{{ stroopwafel_repo }}" - dest: "{{ stroopwafel_dir }}" - version: "{{ stroopwafel_version }}" - update: "{{ stroopwafel_update | default(false) }}" - accept_hostkey: true - force: false - become_user: "{{ stroopwafel_git_user | default(omit) }}" +- import_tasks: gitea_checkout.yml + vars: + checkout_repo: "{{ stroopwafel_repo }}" + checkout_dest: "{{ stroopwafel_dir }}" + checkout_version: "{{ stroopwafel_version }}" - name: Deploy stroopwafel .env copy: content: "{{ stroopwafel_env_b64 | b64decode }}" dest: "{{ stroopwafel_dir }}/.env" owner: root group: "{{ service_group | default('aurbis') }}" - mode: "0640" + mode: "0660" when: stroopwafel_env_b64 is defined no_log: true - name: Copy docker-compose file @@ -39,3 +27,8 @@ community.docker.docker_compose_v2: project_src: "{{ stroopwafel_dir }}" build: policy +- name: Restart stroopwafel on new code + community.docker.docker_compose_v2: + project_src: "{{ stroopwafel_dir }}" + state: restarted + when: checkout_pull is changed