summaryrefslogtreecommitdiffstats
path: root/ansible/roles/resource-data/tasks/unarchive-resource.yml
diff options
context:
space:
mode:
Diffstat (limited to 'ansible/roles/resource-data/tasks/unarchive-resource.yml')
-rw-r--r--ansible/roles/resource-data/tasks/unarchive-resource.yml55
1 files changed, 55 insertions, 0 deletions
diff --git a/ansible/roles/resource-data/tasks/unarchive-resource.yml b/ansible/roles/resource-data/tasks/unarchive-resource.yml
new file mode 100644
index 00000000..79fdbfce
--- /dev/null
+++ b/ansible/roles/resource-data/tasks/unarchive-resource.yml
@@ -0,0 +1,55 @@
+---
+#
+# Wrapper to pass through following variables
+# resources_source_host
+# resources_dir
+# resource_source_filename
+# resource_destination_directory
+# And handling target directory creation and possible removal on failure.
+# Idempotence is also handled here as nothing is done if resource_destination_directory
+# was already created.
+#
+# Logically also tranport method selection belongs to here but left it to caller
+# as this is called in a loop causing "package_facts" called many times
+# (not sure if it would matter).
+#
+- name: "Create {{ resource_destination_directory }} directory"
+ file:
+ path: "{{ resource_destination_directory }}"
+ state: directory
+
+- 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: "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"
+ - 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
+ with_items: "{{ files_after_fail.files | difference(original_files.files) }}"
+ when: files_after_fail is defined
+
+ - fail:
+ msg: "Upload of {{ resource_source_filename }} failed"