Fix wrong detection of uploaded resources

Issue-ID: OOM-1596

Change-Id: I091cd558f7574f49dddf4380df24e11141a4b78d
Signed-off-by: Milan Verespej <m.verespej@partner.samsung.com>
diff --git a/ansible/roles/resource-data/tasks/unarchive-nfs-resource.yml b/ansible/roles/resource-data/tasks/unarchive-nfs-resource.yml
index 9baca2f..9f9d92d 100644
--- a/ansible/roles/resource-data/tasks/unarchive-nfs-resource.yml
+++ b/ansible/roles/resource-data/tasks/unarchive-nfs-resource.yml
@@ -21,10 +21,6 @@
         src: "/tmp/resource_data/{{ resource_source_filename }}"
         dest: "{{ resource_destination_directory }}"
         remote_src: yes
-  rescue:
-    - name: Upload failed
-      set_fact:
-        upload_failed: true
   always:
     - name: Unmount resource dir
       mount:
diff --git a/ansible/roles/resource-data/tasks/unarchive-resource.yml b/ansible/roles/resource-data/tasks/unarchive-resource.yml
index 9eafc22..7ccd21e 100644
--- a/ansible/roles/resource-data/tasks/unarchive-resource.yml
+++ b/ansible/roles/resource-data/tasks/unarchive-resource.yml
@@ -17,20 +17,40 @@
   file:
     path: "{{ resource_destination_directory }}"
     state: directory
-  register: create_destination_dir
+
+- name: Check if resources are uploaded
+  stat:
+    path: "{{ resource_destination_directory }}/{{ resource_source_filename }}-uploaded"
+  register: uploaded
 
 - name: "Handle transport of one archive file"
+  when: not uploaded.stat.exists
   block:
-    - name: Re-set upload_failed
-      set_fact:
-        upload_failed: false
+    - name: "Get list of destination directory files"
+      find:
+        path: "{{ resource_destination_directory }}"
+        file_type: any
+      register: original_files
 
     - name: "Unarchive resource {{ resource_source_filename }} from host {{ resources_source_host }}, transport is {{ transport }}"
       include_tasks: "unarchive-{{ transport }}-resource.yml"
-
-    - name: "Remove the destination directory {{ resource_destination_directory }} on error"
-      file:
+    - file:
+        path: "{{ resource_destination_directory }}/{{ resource_source_filename }}-uploaded"
+        state: touch
+  rescue:
+    - name: "Get list of destination directory files"
+      find:
         path: "{{ resource_destination_directory }}"
+        file_type: any
+      register: files_after_fail
+
+    - name: "Cleanup the destination directory {{ resource_destination_directory }} on error"
+      file:
+        path: "{{ item.path }}"
         state: absent
-      when: upload_failed
-  when: create_destination_dir.changed
+      with_items: "{{ files_after_fail.files | difference(original_files.files) }}"
+      when: files_after_fail is defined
+
+    - fail:
+        msg: "Upload of {{ resource_source_filename }} failed"
+
diff --git a/ansible/roles/resource-data/tasks/unarchive-ssh-resource.yml b/ansible/roles/resource-data/tasks/unarchive-ssh-resource.yml
index 4b1b7d7..1385ba5 100644
--- a/ansible/roles/resource-data/tasks/unarchive-ssh-resource.yml
+++ b/ansible/roles/resource-data/tasks/unarchive-ssh-resource.yml
@@ -16,16 +16,14 @@
         mode: 0600
         owner: root
         group: root
-        remote_src: no
 
     - name: Detect if archive is compressed
       shell: >
-        ssh -o StrictHostKeyChecking=no
-        -i /root/.ssh/infra_to_resource.privkey
-        {{ resources_source_host }}
-        'file "{{ resources_dir }}/{{ resource_source_filename }}"'
+        file "{{ resources_dir }}/{{ resource_source_filename }}"
         | grep "compressed"
       register: compressed
+      failed_when: compressed.rc > 1
+      delegate_to: "{{ resources_source_host }}"
 
     - name: Set tar extract options
       set_fact:
@@ -40,10 +38,6 @@
         | tar -C "{{ resource_destination_directory }}" "{{ tar_extract_options }}" -
       args:
         warn: false
-  rescue:
-    - name: Upload failed
-      set_fact:
-        upload_failed: true
   always:
     - name: Remove the ssh private key
       file: