From 280ed197646842e30ebdb64915c39f42c0150c50 Mon Sep 17 00:00:00 2001
From: Andrea Dell'Amico <adellam@isti.cnr.it>
Date: Mon, 2 Oct 2017 15:20:10 +0200
Subject: [PATCH] library/roles/smartgears/smartgears/tasks/smartgears-app.yml:
 Fix the check that we use to find the distribution directory.

---
 smartgears/smartgears/tasks/smartgears-app.yml | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/smartgears/smartgears/tasks/smartgears-app.yml b/smartgears/smartgears/tasks/smartgears-app.yml
index a432b4f..dc81de1 100644
--- a/smartgears/smartgears/tasks/smartgears-app.yml
+++ b/smartgears/smartgears/tasks/smartgears-app.yml
@@ -47,7 +47,7 @@
   shell: /home/{{ smartgears_user }}/stopContainer.sh
   when:
     - smartgears_upgrade or ( smartgears_download | changed )
-    - smartgears_stop_script.exists
+    - smartgears_stop_script.stat.exists
   tags: [ 'smartgears', 'tomcat', 'stop_smartgears_service' ]
 
 - name: Install the additional tomcat default file
@@ -68,7 +68,7 @@
 - name: Install the smartgears app
   become: True
   become_user: '{{ smartgears_user }}'
-  shell: cd {{ smartgears_downloads_dir }}/smartgears-distribution-* ; . /{{ item.user_home }}/.bashrc  ; ./install -s tomcat
+  shell: cd {{ smartgears_downloads_dir }} ; dest_dir=$( find . -type d -name smartgears-distribution-\* | tail -1 ) ; cd $dest_dir ; . /{{ item.user_home }}/.bashrc  ; ./install -s tomcat
   with_items: '{{ tomcat_m_instances }}'
   when:
     - ( smartgears_download | changed )
@@ -122,7 +122,6 @@
   with_items:
     - '{{ smartgears_install_path }}/lib/lib'
     - '{{ smartgears_install_path }}/apps/webapps'
-  when: smartgears_upgrade
   tags: [ 'smartgears', 'smartgears_conf', 'tomcat' ]
 
 - name: Install the script that fetches the scope tokens
@@ -152,7 +151,7 @@
   become: True
   become_user: '{{ smartgears_user }}'
   shell: /usr/local/bin/get-scopes {{ gcube_admin_token | default('') }}
-  when: gcube_admin_token is defined or smartgears_upgrade
+  when: gcube_admin_token is defined or ( smartgears_download | changed )
   notify: Restart smartgears
   tags: [ 'smartgears', 'smartgears_conf', 'tomcat' ]