---
- block: 
    - name: Remove the old quota service files
      file: path={{ smartgears_instance_path }}/webapps/{{ quota_service_name }} state=absent

  become: True
  become_user: '{{ d4science_user }}'
  when: ( not quota_service_install ) or ( smartgears_upgrade ) 
  tags: [ 'smartgears', 'quota_service', 'tomcat' ]
  
- block:
    # NOTE: Install as the smartgears user so we do not mess with the permissions
    - 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_extension | default('war') }} repository_url={{ quota_service_repository_url }} dest={{ smartgears_user_home }}/{{ quota_service_file }}
  
    - name: Create the quota manager working directory
      file: path={{ smartgears_instance_path }}/webapps/{{ quota_service_name }} state=directory owner={{ smartgears_user }} group={{ smartgears_user }}
  
    - name: Unarchive the quota_service war
      unarchive: copy=no src={{ smartgears_user_home }}/{{ quota_service_file }} dest={{ smartgears_instance_path }}/webapps/{{ quota_service_name }} creates={{ smartgears_instance_path }}/webapps/{{ quota_service_name }}/WEB-INF/lib
      notify: Restart smartgears

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