---
- block:
    - name: Remove the old quota plugin 
      shell: rm -f {{ smartgears_instance_path }}/webapps/{{ smart_executor_name }}/WEB-INF/lib/{{ quota_se_plugin_artifact_id }}-*-jar-with-dependencies.jar
      notify: Restart smartgears
    
  become: True
  become_user: '{{ smartgears_user }}'
  when: not quota_se_plugin_install 
  tags: [ 'smartgears', 'quota_se', 'tomcat' ]

- block:
    - name: Get the quota plugin and install it inside the smart executor
      maven_artifact: artifact_id={{ quota_se_plugin_name }} version={{ quota_se_plugin_version | default(omit) }} group_id={{ quota_se_plugin_group_id }} extension={{ quota_se_plugin_extension | default('war') }} repository_url={{ smartgears_global_base_url }} classifier={{ quota_se_plugin_classifier }} dest={{ smartgears_downloads_dir }}/{{ quota_se_plugin_file }} verify_checksum=always
      register: quota_storage_download
    
    - name: Remove the old quota plugin 
      shell: rm -f {{ smartgears_instance_path }}/webapps/{{ smart_executor_name }}/WEB-INF/lib/{{ quota_se_plugin_artifact_id }}-*-jar-with-dependencies.jar
      when: quota_storage_download is changed

    - name: Copy the quota plugin to its final destination
      copy: src={{ smartgears_downloads_dir }}/{{ quota_se_plugin_file }} dest={{ smartgears_instance_path }}/webapps/{{ smart_executor_name }}/WEB-INF/lib/{{ quota_se_plugin_file }} remote_src=yes
      notify: Restart smartgears

  become: True
  become_user: '{{ smartgears_user }}'
  when: quota_se_plugin_install 
  tags: [ 'smartgears', 'quota_se', 'tomcat' ]