diff --git a/roles/harbor/tasks/main.yml b/roles/harbor/tasks/main.yml index 7f9804e..6ab5174 100644 --- a/roles/harbor/tasks/main.yml +++ b/roles/harbor/tasks/main.yml @@ -52,6 +52,15 @@ tags: - update_config +# work around for DEV-271("container start failure after reboot") +- name: Ensure systemd file + template: + src: harbor-systemd.service.j2 + dest: /etc/systemd/system/harbor.service + owner: root + group: root + mode: 0755 + - name: Ensure config files are populated from from templates/harbor copy: src: "{{ item.src }}" @@ -64,16 +73,34 @@ tags: - update_config + + +- name: "Check if harbor tarball exists" + stat: + path: '{{ service_base_path }}/{{ inventory_hostname }}/harbor-offline-installer-{{ harbor_version }}.tgz' + register: harbor_tarball + + + - name: Download harbor offline installer ansible.builtin.get_url: url: https://github.com/goharbor/harbor/releases/download/{{ harbor_version }}/harbor-offline-installer-{{ harbor_version }}.tgz dest: "{{ service_base_path }}/{{ inventory_hostname }}/harbor-offline-installer-{{ harbor_version }}.tgz" + when: + - not harbor_tarball.stat.exists + +- name: "Check if {{ inventory_hostname }}/harbor/docker-compose.yml exists" + stat: + path: '{{ service_base_path }}/{{ inventory_hostname }}/harbor/docker-compose.yml' + register: harbor_installation - name: Extract harbor-offline-installer-{{ harbor_version }}.tgz into {{ service_base_path }}/{{ inventory_hostname }} ansible.builtin.unarchive: src: "{{ service_base_path }}/{{ inventory_hostname }}/harbor-offline-installer-{{ harbor_version }}.tgz" dest: "{{ service_base_path }}/{{ inventory_hostname }}" remote_src: yes + when: + - not harbor_installation.stat.exists - name: "Check if {{ inventory_hostname }}/harbor/docker-compose.yml exists" stat: @@ -82,11 +109,9 @@ tags: - update_deployment -- name: "Stop {{ inventory_hostname }}" - shell: docker-compose down - args: - chdir: '{{ service_base_path }}/{{ inventory_hostname }}/harbor' - when: check_docker_compose_file.stat.exists - ignore_errors: yes - tags: - - update_deployment +- name: "Ensure harbor is running" + systemd: + name: harbor + enabled: yes + state: started + daemon_reload: yes diff --git a/roles/harbor/templates/harbor-systemd.service.j2 b/roles/harbor/templates/harbor-systemd.service.j2 new file mode 100644 index 0000000..94096b9 --- /dev/null +++ b/roles/harbor/templates/harbor-systemd.service.j2 @@ -0,0 +1,21 @@ +# +# there is an issue of start order after e.g. rebooting the VM +# https://github.com/goharbor/harbor/issues/7008 +# work around via adding systemd file +# +# +[Unit] +Description=Harbor +After=docker.service systemd-networkd.service systemd-resolved.service +Requires=docker.service +Documentation=http://github.com/vmware/harbor + +[Service] +Type=simple +Restart=on-failure +RestartSec=5 +ExecStart=/usr/bin/docker-compose -f {{ service_base_path }}/{{ inventory_hostname }}/harbor/docker-compose.yml up +ExecStop=/usr/bin/docker-compose -f {{ service_base_path }}/{{ inventory_hostname }}/harbor/docker-compose.yml down + +[Install] +WantedBy=multi-user.target