blob: 79fdbfce6809d1ece8db7d022414d6d471061292 [file] [log] [blame]
Samuli Silvius29886f02019-02-19 16:00:37 +02001---
2#
3# Wrapper to pass through following variables
4# resources_source_host
5# resources_dir
6# resource_source_filename
7# resource_destination_directory
8# And handling target directory creation and possible removal on failure.
9# Idempotence is also handled here as nothing is done if resource_destination_directory
10# was already created.
11#
12# Logically also tranport method selection belongs to here but left it to caller
13# as this is called in a loop causing "package_facts" called many times
14# (not sure if it would matter).
15#
16- name: "Create {{ resource_destination_directory }} directory"
17 file:
18 path: "{{ resource_destination_directory }}"
19 state: directory
Milan Verespejad41e6d2019-03-01 14:49:25 +010020
21- name: Check if resources are uploaded
22 stat:
23 path: "{{ resource_destination_directory }}/{{ resource_source_filename }}-uploaded"
24 register: uploaded
Samuli Silvius29886f02019-02-19 16:00:37 +020025
26- name: "Handle transport of one archive file"
Milan Verespejad41e6d2019-03-01 14:49:25 +010027 when: not uploaded.stat.exists
Samuli Silvius29886f02019-02-19 16:00:37 +020028 block:
Milan Verespejad41e6d2019-03-01 14:49:25 +010029 - name: "Get list of destination directory files"
30 find:
31 path: "{{ resource_destination_directory }}"
32 file_type: any
33 register: original_files
Samuli Silvius29886f02019-02-19 16:00:37 +020034
35 - name: "Unarchive resource {{ resource_source_filename }} from host {{ resources_source_host }}, transport is {{ transport }}"
36 include_tasks: "unarchive-{{ transport }}-resource.yml"
Milan Verespejad41e6d2019-03-01 14:49:25 +010037 - file:
38 path: "{{ resource_destination_directory }}/{{ resource_source_filename }}-uploaded"
39 state: touch
40 rescue:
41 - name: "Get list of destination directory files"
42 find:
Samuli Silvius29886f02019-02-19 16:00:37 +020043 path: "{{ resource_destination_directory }}"
Milan Verespejad41e6d2019-03-01 14:49:25 +010044 file_type: any
45 register: files_after_fail
46
47 - name: "Cleanup the destination directory {{ resource_destination_directory }} on error"
48 file:
49 path: "{{ item.path }}"
Samuli Silvius29886f02019-02-19 16:00:37 +020050 state: absent
Milan Verespejad41e6d2019-03-01 14:49:25 +010051 with_items: "{{ files_after_fail.files | difference(original_files.files) }}"
52 when: files_after_fail is defined
53
54 - fail:
55 msg: "Upload of {{ resource_source_filename }} failed"