---
- block:
    - name: Remove the old catalogue ws files
      file: path={{ smartgears_instance_path }}/webapps/{{ catalogue_ws_name }} state=absent
      when: catalogue_ws_upgrade

    # NOTE: Install as the smartgears user so we do not mess with the permissions
    - name: Get the catalogue-ws
      maven_artifact: artifact_id={{ catalogue_ws_name }} version={{ catalogue_ws_version | default(omit) }} group_id={{ catalogue_ws_group_id }} extension={{ catalogue_ws_extension | default('war') }} repository_url={{ smartgears_global_base_url }} dest={{ smartgears_user_home }}/{{ catalogue_ws_file }}
  
    - name: Create the catalogue ws working directory
      file: path={{ smartgears_instance_path }}/webapps/{{ catalogue_ws_name }} state=directory owner={{ smartgears_user }} group={{ smartgears_user }}
  
    - name: Unarchive the catalogue ws war
      unarchive: copy=no src={{ smartgears_user_home }}/{{ catalogue_ws_file }} dest={{ smartgears_instance_path }}/webapps/{{ catalogue_ws_name }} creates={{ smartgears_instance_path }}/webapps/{{ catalogue_ws_name }}/WEB-INF/lib
      notify: Restart smartgears

  become: True
  become_user: '{{ d4science_user }}'
  when: catalogue_ws_install 
  tags: [ 'smartgears', 'catalogue_ws', 'tomcat' ]

- block:
    - name: Remove the old catalogue ws files
      file: path={{ smartgears_instance_path }}/webapps/{{ catalogue_ws_name }} state=absent

  become: True
  become_user: '{{ d4science_user }}'
  when: not catalogue_ws_install 
  tags: [ 'smartgears', 'catalogue_ws', 'tomcat' ]