---
- block:
    - name: Remove the old tabulardata files
      file: path={{ item }} state=absent
      with_items:
        - '{{ smartgears_instance_path }}/webapps/{{ tabular_data_name }}'
        - '{{ smartgears_instance_path }}/webapps/{{ tabular_data_name }}.{{ tabular_extension }}'

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

- block:
    - name: Get the tabular-data-service 
      maven_artifact: artifact_id={{ tabular_data_name }} version={{ tabular_data_version | default('latest') }} group_id={{ tabular_group_id }} extension={{ tabular_extension }} repository_url={{ smartgears_global_base_url }} dest={{ smartgears_downloads_dir }}/{{ tabular_data_file }}  verify_checksum=always
      register: tabular_data_download
  
    - name: Remove the old tabulardata files
      file: path={{ smartgears_instance_path }}/webapps/{{ tabular_data_name }} state=absent
      when: ( tabular_data_download | change )

    - name: Copy the tabular data war into the webapps directory
      copy: src={{ smartgears_downloads_dir }}/{{ tabular_data_file }} dest={{ smartgears_instance_path }}/webapps/{{ tabular_data_name }}.{{ tabular_extension }} remote_src=yes force=yes
      notify: Restart smartgears

  become: True
  become_user: '{{ d4science_user }}'
  when: tabular_data_install 
  tags: [ 'smartgears', 'tabular_data', 'tomcat' ]