Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Commit

Permalink
Merge branch '34-reconfigure-error-handling' into 'main'
Browse files Browse the repository at this point in the history
Reconfigure GitLab if a previous reconfiguration had failed

Closes #34

See merge request hifis/ansible/gitlab-role!35
  • Loading branch information
Normo committed Feb 22, 2021
2 parents 0fa7b95 + 61a4162 commit b62865e
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 53 deletions.
6 changes: 4 additions & 2 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
53 changes: 53 additions & 0 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -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

...
37 changes: 29 additions & 8 deletions tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'

...
55 changes: 12 additions & 43 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

...
33 changes: 33 additions & 0 deletions tasks/reconfigure.yml
Original file line number Diff line number Diff line change
@@ -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

...

0 comments on commit b62865e

Please sign in to comment.