blob: 879a9dfe4f6b3ccece1506b79045e9e7d4782140 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
---
#
# Wrapper to pass through following variables:
# resources_source_host
# resources_dir
# resource_source_filename
# resource_destination_directory
# and handle target directory creation and eventual 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"
- name: "Generate flag file after resources are deployed on infra"
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: "{{ files_item.path }}"
state: absent
loop: "{{ files_after_fail.files | difference(original_files.files) }}"
loop_control:
label: "{{ files_item.path }}"
loop_var: files_item
when: files_after_fail is defined
- name: "Report failure of upload operation"
fail:
msg: "Upload of {{ resource_source_filename }} failed"
|