---

- name: "Validate Gitlab's configuration file"
  become: true
  ansible.builtin.command: gitlab-ctl show-config
  register: config_file_validation
  changed_when: false
  failed_when: config_file_validation.rc != 0

- name: Reconfigure Gitlab
  when: config_file_validation is not failed
  become: true
  ansible.builtin.command: gitlab-ctl reconfigure
  register: reconfiguration
  changed_when:
    - reconfiguration.rc == 0
    - >-
      (
        reconfiguration.stdout
        | regex_findall('Infra Phase complete, .*')
      ) is not search('0/')
  failed_when: reconfiguration.rc != 0
