---
- block:
    - name: Remove the old tabulardata files
      file: path={{ smartgears_instance_path }}/webapps/{{ tabular_data_name }} state=absent
      when: tabular_data_upgrade

    # NOTE: Install as the smartgears user so we do not mess with the permissions
    - name: Get the tabular-data-service 
      maven_artifact: artifact_id={{ tabular_data_name }} version={{ tabular_data_version | default(omit) }} group_id={{ tabular_group_id }} extension={{ tabular_extension | default('war') }} repository_url={{ tabular_service_repository_url }} dest={{ smartgears_user_home }}/{{ tabular_data_file }}
  
    - name: Create the tabular data  working directory
      file: path={{ smartgears_instance_path }}/webapps/{{ tabular_data_name }} state=directory owner={{ smartgears_user }} group={{ smartgears_user }}
  
    - name: Unarchive the tabular data  war
      unarchive: copy=no src={{ smartgears_user_home }}/{{ tabular_data_file }} dest={{ smartgears_instance_path }}/webapps/{{ tabular_data_name }} creates={{ smartgears_instance_path }}/webapps/{{ tabular_data_name }}/WEB-INF/lib
      notify: Restart smartgears

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

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

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