---
- name: Checkout engine-block branch
  git: repo=https://github.com/OpenConext/OpenConext-engineblock.git dest="{{ engine_branch_dir }}" version={{ engine_branch }} force=yes
  when: engine_branch != ''
  register: eb_gitclone

- name: Make release
  command: "./bin/makeRelease.sh {{ engine_branch }}"
  args:
    chdir: "{{ engine_branch_dir }}"
  when: eb_gitclone.changed

- name: Unpack current version
  unarchive: src="~/Releases/OpenConext-engineblock-{{ engine_branch }}.tar.gz" dest="{{ openconext_releases_dir }}" copy=no
  when: eb_gitclone.changed

- name: Activate new EngineBlock branch
  file: src="{{ openconext_releases_dir }}/OpenConext-engineblock-{{ engine_branch }}" dest={{ engine_current_release_symlink }} state=link
  notify:
    - restart httpd
  when: eb_gitclone.changed

---
- name: Check if target dir exists
  stat: path={{ engine_release_dir }}
  register: eb_dir

- name: Checkout engine-block branch
  git: >
    repo=https://github.com/OpenConext/OpenConext-engineblock.git
    dest="{{ engine_branch_dir }}"
    version={{ engine_branch }}
    force=yes
  register: eb_gitclone

- name: Make release
  command: "./bin/makeRelease.sh {{ engine_branch }}"
  args:
    chdir: "{{ engine_branch_dir }}"
  when: eb_gitclone.changed or not eb_dir.stat.exists

- name: Unpack current version
  unarchive: >
    src="~/Releases/OpenConext-engineblock-{{ engine_branch }}.tar.gz"
    dest="{{ openconext_releases_dir }}"
    copy=no
  when: eb_gitclone.changed or not eb_dir.stat.exists

- name: Activate new EngineBlock branch
  file: >
    src="{{ openconext_releases_dir }}/OpenConext-engineblock-{{ engine_branch }}"
    dest={{ engine_current_release_symlink }}
    state=link
  notify:
    - restart httpd

Fix deployment of EB in cases where /opt/openconext was forcibly removed
Fix deployment of EB in cases where /opt/openconext was forcibly removed