---
- block: 
    - name: Remove the old gcube oauth files
      file: path={{ smartgears_instance_path }}/webapps/{{ gcube_oauth_name }} state=absent

  become: True
  become_user: '{{ d4science_user }}'
  when: ( not gcube_oauth_install ) or ( smartgears_upgrade ) 
  tags: [ 'smartgears', 'gcube_oauth', 'tomcat' ]
  
- block:
    # NOTE: Install as the smartgears user so we do not mess with the permissions
    - name: Get the gcube-oauth war
      maven_artifact: artifact_id={{ gcube_oauth_name }} version={{ gcube_oauth_version | default(omit) }} group_id={{ gcube_oauth_group_id }} extension={{ gcube_oauth_extension | default('war') }} repository_url={{ gcube_oauth_repository_url }} dest={{ smartgears_user_home }}/{{ gcube_oauth_file }}
  
    - name: Create the data trasfer working directory
      file: path={{ smartgears_instance_path }}/webapps/gcube-{{ gcube_oauth_name }} state=directory owner={{ smartgears_user }} group={{ smartgears_user }}
  
    - name: Unarchive the gcube_oauth war
      unarchive: copy=no src={{ smartgears_user_home }}/{{ gcube_oauth_file }} dest={{ smartgears_instance_path }}/webapps/gcube-{{ gcube_oauth_name }} creates={{ smartgears_instance_path }}/webapps/{{ gcube_oauth_name }}/WEB-INF/lib
      notify: Restart smartgears

  become: True
  become_user: '{{ d4science_user }}'
  when: gcube_oauth_install 
  tags: [ 'smartgears', 'gcube_oauth', 'tomcat' ]