---
- block:
    - name: Remove the old sdi files
      file: path={{ smartgears_instance_path }}/webapps/{{ sdi_service_name }} state=absent
      when: sdi_service_upgrade

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

  become: True
  become_user: '{{ d4science_user }}'
  when: sdi_service_install 
  tags: [ 'smartgears', 'sdi_service', 'tomcat' ]

- block:
    - name: Remove the old sdi files
      file: path={{ smartgears_instance_path }}/webapps/{{ sdi_service_name }} state=absent

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