---
- block: 
    - name: Remove the old quota service files
      file: path={{ item }} state=absent
      with_items:
        - '{{ smartgears_instance_path }}/webapps/{{ quota_service_name }}'
        - '{{ smartgears_instance_path }}/webapps/{{ quota_service_name }}.{{ quota_service_extension }}'        
      notify: Restart smartgears

  become: True
  become_user: '{{ d4science_user }}'
  when: not quota_service_install
  tags: [ 'smartgears', 'quota_service', 'tomcat' ]
  
- block:
    - name: Get the quota-service war
      maven_artifact: artifact_id={{ quota_service_name }} version={{ quota_service_version | default(omit) }} group_id={{ quota_group_id }} extension={{ quota_service_extension | default('war') }} repository_url={{ smartgears_global_base_url }} dest={{ smartgears_downloads_dir }}/{{ quota_service_file }} verify_checksum=always
      register: quota_service_download
  
    - name: Remove the old quota service files
      file: path={{ smartgears_instance_path }}/webapps/{{ quota_service_name }} state=absent
      when: quota_service_download is changed

    - name: Copy the quota_service war to the destination place
      copy: src={{ smartgears_downloads_dir }}/{{ quota_service_file }} dest={{ smartgears_instance_path }}/webapps/{{ quota_service_name }}.{{ quota_service_extension }} remote_src=yes force=yes 
      notify: Restart smartgears

  become: True
  become_user: '{{ d4science_user }}'
  when: quota_service_install 
  tags: [ 'smartgears', 'quota_service', 'tomcat' ]