---
- block:
    - name: Remove the old grsf-api files
      file: path={{ item }} state=absent
      with_items:
        - '{{ smartgears_instance_path }}/webapps/{{ uri_resolver_name }}'
        - '{{ smartgears_instance_path }}/webapps/{{ uri_resolver_name }}.{{ uri_resolver_extension }}'
      notify: Restart smartgears

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

- block:
    - name: Get the grsf-api war
      maven_artifact: artifact_id={{ uri_resolver_name }} version={{ uri_resolver_version | default(omit) }} group_id={{ uri_resolver_group_id }} extension={{ uri_resolver_extension | default('war') }} repository_url={{ smartgears_global_base_url }} dest={{ smartgears_downloads_dir }}/{{ uri_resolver_file }}
      register: uri_resolver_download
  
    - name: Remove the old grsf-api files
      file: path={{ smartgears_instance_path }}/webapps/{{ uri_resolver_name }} state=absent
      notify: Restart smartgears
      when: uri_resolver_download is changed
  
    - name: Copy the GRSF api war file into the webapps directory
      copy: src={{ smartgears_downloads_dir }}/{{ uri_resolver_file }} dest={{ smartgears_instance_path }}/webapps/{{ uri_resolver_name }}.{{ uri_resolver_extension }} remote_src=yes force=yes
      notify: Restart smartgears

  become: True
  become_user: '{{ d4science_user }}'
  tags: [ 'smartgears', 'uri_resolver', 'tomcat' ]
  when: uri_resolver_install