From bf6ddb08e6d8e6a41395c28ca8fb6aaf0dc8002c Mon Sep 17 00:00:00 2001 From: "flyingscorpio@clevo" Date: Wed, 18 Jan 2023 10:29:33 +0100 Subject: [PATCH] Add repos tasks for forgejo --- roles/forgejo/tasks/main.yml | 3 +++ roles/forgejo/tasks/repos.yml | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 roles/forgejo/tasks/repos.yml diff --git a/roles/forgejo/tasks/main.yml b/roles/forgejo/tasks/main.yml index 14d9be1..bdff495 100644 --- a/roles/forgejo/tasks/main.yml +++ b/roles/forgejo/tasks/main.yml @@ -23,3 +23,6 @@ # fail2ban tasks need the forgejo log file, which should be created when forgejo runs - name: Include fail2ban tasks ansible.builtin.include_tasks: fail2ban.yml + +- name: Include repos tasks + ansible.builtin.include_tasks: repos.yml diff --git a/roles/forgejo/tasks/repos.yml b/roles/forgejo/tasks/repos.yml new file mode 100644 index 0000000..e60fec7 --- /dev/null +++ b/roles/forgejo/tasks/repos.yml @@ -0,0 +1,34 @@ +--- +- name: Ask to push latest forgejo_dump zipfile + ansible.builtin.pause: + prompt: "Local path to forgejo dump, so we can push it [leave empty to not push]" + echo: true + register: user_forgejo_dump_path + +- name: Push latest forgejo dump zipfile + become: true + ansible.builtin.copy: + src: "{{ user_forgejo_dump_path.user_input }}" + dest: "{{ forgejo_run_dir }}/forgejo-dumps/{{ user_forgejo_dump_path.user_input | basename }}" + owner: git + group: git + mode: 0640 + when: user_forgejo_dump_path.user_input != '' + +- name: Find all forgejo dumps on the server + become: true + ansible.builtin.find: + paths: "{{ forgejo_run_dir }}/forgejo-dumps/" + register: all_forgejo_dumps + +- name: Find latest forgejo dump on the server + ansible.builtin.set_fact: + latest_forgejo_dump: "{{ all_forgejo_dumps.files | sort(attribute='mtime') | last }}" + +- name: Deploy repos from latest forgejo dump + become: true + become_user: git + ansible.builtin.command: + cmd: "/usr/local/bin/forgejo_backup.sh restore {{ latest_forgejo_dump.path }}" + # when this dir exists, the command won't run, so we don't overwrite existing repos + creates: "{{ forgejo_run_dir }}/forgejo-repositories"