diff --git a/handlers/main.yml b/handlers/main.yml index 7a709d5..9dbd0a9 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -12,7 +12,8 @@ - name: Reconfigure Primary GitLab become: yes - command: gitlab-ctl reconfigure + ansible.builtin.shell: + cmd: gitlab-ctl reconfigure || (touch /etc/gitlab/reconfigure_failed && /bin/false) register: gitlab_reconfigure environment: SKIP_POST_DEPLOYMENT_MIGRATIONS: true @@ -21,7 +22,8 @@ - name: Reconfigure Non Primary GitLab become: yes - command: gitlab-ctl reconfigure + ansible.builtin.shell: + cmd: gitlab-ctl reconfigure || (touch /etc/gitlab/reconfigure_failed && /bin/false) register: gitlab_reconfigure listen: GitLab has been installed or upgraded when: not gitlab_is_primary diff --git a/tasks/configure.yml b/tasks/configure.yml new file mode 100644 index 0000000..242e77f --- /dev/null +++ b/tasks/configure.yml @@ -0,0 +1,53 @@ +# SPDX-FileCopyrightText: 2021 Helmholtz Centre for Environmental Research (UFZ) +# SPDX-FileCopyrightText: 2021 Helmholtz-Zentrum Dresden-Rossendorf (HZDR) +# +# SPDX-License-Identifier: Apache-2.0 + +--- + +- name: Copy gitlab-secrets.json + copy: + src: "{{ gitlab_secrets_file }}" + dest: /etc/gitlab/gitlab-secrets.json + owner: root + group: root + mode: '0600' + backup: yes + when: gitlab_secrets_file is defined + notify: + - Reconfigure Primary GitLab + - Reconfigure Non Primary GitLab + +- name: Copy GitLab Configuration File. + become: yes + template: + src: "{{ gitlab_configuration_file_template }}" + dest: "{{ gitlab_configuration_file_path }}" + owner: root + group: root + mode: '0644' + notify: + - Reconfigure Primary GitLab + - Reconfigure Non Primary GitLab + +- name: Create file to prevent Gitlab to restart before migrations + copy: + content: "" + dest: /etc/gitlab/skip-auto-reconfigure + force: no + owner: root + group: root + mode: '0644' + when: gitlab_is_primary + +- name: Create file to prevent Gitlab to backup database + copy: + content: "" + dest: /etc/gitlab/skip-auto-backup + force: no + owner: root + group: root + mode: '0644' + when: not gitlab_is_primary + +... diff --git a/tasks/install.yml b/tasks/install.yml index a07a4e6..828cd6c 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -87,13 +87,34 @@ - gitlab_is_primary is defined - gitlab_is_primary -- name: Install or upgrade GitLab. - become: yes - package: - name: "{{ gitlab_package_name }}" - state: present - update_cache: yes - register: gitlab_install_output - notify: GitLab has been installed or upgraded +- block: + + - name: Install or upgrade GitLab. + become: yes + package: + name: "{{ gitlab_package_name }}" + state: present + update_cache: yes + register: gitlab_install_output + notify: GitLab has been installed or upgraded + + rescue: + + - name: Ensure GitLab directory exists + file: + path: /etc/gitlab + state: directory + owner: root + group: root + mode: '0775' + + - name: Create file to detect a failed reconfigure + copy: + content: "This file is managed by Ansible." + dest: /etc/gitlab/reconfigure_failed + force: no + owner: root + group: root + mode: '0644' ... diff --git a/tasks/main.yml b/tasks/main.yml index d52ed23..4a7f1c0 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -8,53 +8,22 @@ - name: Set OS distribution dependent variables include_vars: "{{ ansible_facts['distribution'] }}.yml" +- name: Check if a previous reconfigure had failed + ansible.builtin.stat: + path: /etc/gitlab/reconfigure_failed + register: reconfigure_failed + +- name: Reconfigure GitLab + include: reconfigure.yml + become: yes + when: reconfigure_failed.stat.exists + - name: Install GitLab include: install.yml become: yes -- name: Copy gitlab-secrets.json - copy: - src: "{{ gitlab_secrets_file }}" - dest: /etc/gitlab/gitlab-secrets.json - owner: root - group: root - mode: '0600' - backup: yes - when: gitlab_secrets_file is defined - notify: - - Reconfigure Primary GitLab - - Reconfigure Non Primary GitLab - -- name: Copy GitLab Configuration File. +- name: Configure GitLab + include: configure.yml become: yes - template: - src: "{{ gitlab_configuration_file_template }}" - dest: "{{ gitlab_configuration_file_path }}" - owner: root - group: root - mode: '0644' - notify: - - Reconfigure Primary GitLab - - Reconfigure Non Primary GitLab - -- name: Create file to prevent Gitlab to restart before migrations - copy: - content: "" - dest: /etc/gitlab/skip-auto-reconfigure - force: no - owner: root - group: root - mode: '0644' - when: gitlab_is_primary - -- name: Create file to prevent Gitlab to backup database - copy: - content: "" - dest: /etc/gitlab/skip-auto-backup - force: no - owner: root - group: root - mode: '0644' - when: not gitlab_is_primary ... diff --git a/tasks/reconfigure.yml b/tasks/reconfigure.yml new file mode 100644 index 0000000..bcd3ea2 --- /dev/null +++ b/tasks/reconfigure.yml @@ -0,0 +1,33 @@ +# SPDX-FileCopyrightText: 2021 Helmholtz Centre for Environmental Research (UFZ) +# SPDX-FileCopyrightText: 2021 Helmholtz-Zentrum Dresden-Rossendorf (HZDR) +# +# SPDX-License-Identifier: Apache-2.0 + +--- +- name: Ensure gitlab-ctl file exists + ansible.builtin.stat: + path: /usr/bin/gitlab-ctl + register: gitlab_ctl + +- name: Reconfigure Primary GitLab + become: yes + ansible.builtin.command: gitlab-ctl reconfigure + environment: + SKIP_POST_DEPLOYMENT_MIGRATIONS: true + when: + - gitlab_is_primary + - gitlab_ctl.stat.exists + +- name: Reconfigure Non Primary GitLab + become: yes + ansible.builtin.command: gitlab-ctl reconfigure + when: + - not gitlab_is_primary + - gitlab_ctl.stat.exists + +- name: Remove file that indicates a failed reconfigure + ansible.builtin.file: + path: /etc/gitlab/reconfigure_failed + state: absent + +...