From fbca3de150da86e3fc5f252b58669d131a6157ac Mon Sep 17 00:00:00 2001
From: Andrea Dell'Amico <adellam@isti.cnr.it>
Date: Mon, 25 Sep 2017 16:47:23 +0200
Subject: [PATCH] accounting-service: fix the upgrade scenario.

---
 smartgears/accounting-service/tasks/main.yml | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/smartgears/accounting-service/tasks/main.yml b/smartgears/accounting-service/tasks/main.yml
index eec661f..102fdd3 100644
--- a/smartgears/accounting-service/tasks/main.yml
+++ b/smartgears/accounting-service/tasks/main.yml
@@ -5,6 +5,7 @@
       with_items:
         - '{{ smartgears_instance_path }}/webapps/{{ accounting_service_name }}'
         - '{{ smartgears_instance_path }}/webapps/{{ accounting_service_name }}.{{ accounting_service_extension }}'
+      notify: Restart smartgears
 
   become: True
   become_user: '{{ smartgears_user }}'
@@ -14,7 +15,12 @@
 - block:
     - name: Get the accounting_service war
       maven_artifact: artifact_id={{ accounting_service_name }} version={{ accounting_service_version | default('latest') }} group_id={{ accounting_service_group_id }} extension={{ accounting_service_extension | default('war') }} repository_url={{ smartgears_global_base_url }} dest={{ smartgears_downloads_dir }}/{{ accounting_service_file }}
+      register: accounting_download
   
+    - name: Remove the accounting service app
+      file: dest={{ smartgears_instance_path }}/webapps/{{ accounting_service_name }} state=absent
+      when: ( accounting_download | changed )
+
     - name: Copy the accounting_service war file to the destination place
       copy: src={{ smartgears_downloads_dir }}/{{ accounting_service_file }} dest={{ smartgears_instance_path }}/webapps/{{ accounting_service_name }}.{{ accounting_service_extension }} remote_src=yes force=yes
       notify: Restart smartgears