diff --git a/defaults/main.yml b/defaults/main.yml index d7c7d6f..dd4f1ab 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -7,7 +7,7 @@ forgejo_group: 'git' forgejo_confdir: '/etc/forgejo/app.ini' forgejo_dump_path: '/srv/forgejo-dump' forgejo_flavor: 'forgejo' -forgejo_version: '7.0.4' +forgejo_version: '7.0.5' #forgejo_version: '1.21.7-0' forgejo_arch: 'linux-amd64' #forgejo_download_url: 'https://github.com/go-gitea/gitea/releases/download/v{{ forgejo_version }}/gitea-{{ forgejo_version }}-{{ forgejo_arch }}' @@ -49,7 +49,7 @@ forgejo_database_config: - 'SSL_MODE = disable' forgejo_repository_config: - - 'ROOT = /home/git/forgejo-repositories' + - 'ROOT = {{ forgejo_lib_dir }}/gitea-repositories' forgejo_server_config: - 'SSH_DOMAIN = git.example.org' diff --git a/handlers/main.yml b/handlers/main.yml index 054f2cf..9e40294 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -4,3 +4,8 @@ systemd: name: forgejo state: restarted + +- name: 'Stop forgejo' + systemd: + name: forgejo + state: stopped \ No newline at end of file diff --git a/tasks/install_upgrade.yml b/tasks/install_upgrade.yml index b329e3d..118d0f7 100644 --- a/tasks/install_upgrade.yml +++ b/tasks/install_upgrade.yml @@ -16,17 +16,30 @@ forgejo_download_url: '{{ forgejo_url.stdout }}' when: forgejo_flavor == 'forgejo' -- name: '[INSTALL] - Check if forgejo is installed' +- name: '[INSTALL] - Check if forgejo is already installed' shell: cmd: '{{ forgejo_bindir }}/forgejo --version -c {{ forgejo_confdir }}' register: forgejo_is_installed + ignore_errors: true # needed when forgejo is not yet installed -- name: '[UPGRADE] - Check forgejo health' +# The following task is needed for the doctor check task, as `gitea-repositories` needs to exist, +# but is created only when the first user creates a repo # so doctor gives an error on first installation +# and on other installation if no user has created any repo yet. +# It also allows to make sure forgejo was installed and used. +- name: '[INSTALL] - Check gitea-repositories exists' + stat: + path: "{{ forgejo_lib_dir }}/gitea-repositories" + register: gitea_repositories + +- name: '[UPGRADE] - Check forgejo health with doctor before updating' shell: cmd: '{{ forgejo_bindir }}/forgejo doctor check --all -c {{ forgejo_confdir }}' become: 'yes' become_user: '{{ forgejo_user }}' register: forgejo_health + when: + - forgejo_is_installed.rc == 0 + - gitea_repositories.stat.exists - name: '[UPGRADE] - Restart forgejo' systemd: @@ -34,11 +47,14 @@ state: restarted when: - forgejo_is_installed.rc == 0 - - forgejo_health.rc == 0 + - forgejo_health is defined and forgejo_health.rc is defined and forgejo_health.rc == 0 - name: '[UPGRADE] - Wait for forgejo to be back online' pause: seconds: 10 + when: + - forgejo_is_installed.rc == 0 + - forgejo_health is defined and forgejo_health.rc is defined and forgejo_health.rc == 0 - name: '[UPGRADE] - Flush all queues' shell: @@ -47,7 +63,7 @@ become_user: '{{ forgejo_user }}' when: - forgejo_is_installed.rc == 0 - - forgejo_health.rc == 0 + - forgejo_health is defined and forgejo_health.rc is defined and forgejo_health.rc == 0 - name: '[UPGRADE] - Stop forgejo' systemd: @@ -55,8 +71,7 @@ state: stopped when: - forgejo_is_installed.rc == 0 - - forgejo_health.rc == 0 - + - forgejo_health is defined and forgejo_health.rc is defined and forgejo_health.rc == 0 - name: '[INSTALL] - Download forgejo binary' get_url: @@ -67,7 +82,6 @@ group: '{{ forgejo_group }}' force: 'yes' notify: 'Restart forgejo' - - name: '[INSTALL] - Set /etc/forgejo rights to read-only' file: @@ -79,31 +93,21 @@ path: '/etc/forgejo/app.ini' mode: '0640' -- name: '[UPGRADE] - Start forgejo' - systemd: - name: forgejo - state: started - when: - - forgejo_is_installed.rc == 0 - - forgejo_health.rc == 0 - -- name: '[UPGRADE] - Check forgejo health' +- name: '[UPGRADE] - Check forgejo health after upgrading' shell: cmd: '{{ forgejo_bindir }}/forgejo doctor check --all -c {{ forgejo_confdir }}' become: 'yes' become_user: '{{ forgejo_user }}' register: forgejo_health - -- name: '[UPGRADE] - Stop forgejo. Something is wrong' - systemd: - name: forgejo - state: started - when: - - forgejo_health.rc != 0 + when: + - forgejo_is_installed.rc == 0 + - gitea_repositories.stat.exists - name: '[UPGRADE] - Display problem message' fail: msg: 'Forgejo doctor detected issues after upgrade task. Please check the instance manually and fix issues before continuing' when: - - forgejo_health.rc != 0 + - forgejo_is_installed.rc == 0 + - forgejo_health is defined and forgejo_health.rc is defined and forgejo_health.rc != 0 + notify: 'Stop forgejo'