Samuli Silvius | 29886f0 | 2019-02-19 16:00:37 +0200 | [diff] [blame] | 1 | --- |
| 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 Verespej | ad41e6d | 2019-03-01 14:49:25 +0100 | [diff] [blame] | 20 | |
| 21 | - name: Check if resources are uploaded |
| 22 | stat: |
| 23 | path: "{{ resource_destination_directory }}/{{ resource_source_filename }}-uploaded" |
| 24 | register: uploaded |
Samuli Silvius | 29886f0 | 2019-02-19 16:00:37 +0200 | [diff] [blame] | 25 | |
| 26 | - name: "Handle transport of one archive file" |
Milan Verespej | ad41e6d | 2019-03-01 14:49:25 +0100 | [diff] [blame] | 27 | when: not uploaded.stat.exists |
Samuli Silvius | 29886f0 | 2019-02-19 16:00:37 +0200 | [diff] [blame] | 28 | block: |
Milan Verespej | ad41e6d | 2019-03-01 14:49:25 +0100 | [diff] [blame] | 29 | - name: "Get list of destination directory files" |
| 30 | find: |
| 31 | path: "{{ resource_destination_directory }}" |
| 32 | file_type: any |
| 33 | register: original_files |
Samuli Silvius | 29886f0 | 2019-02-19 16:00:37 +0200 | [diff] [blame] | 34 | |
| 35 | - name: "Unarchive resource {{ resource_source_filename }} from host {{ resources_source_host }}, transport is {{ transport }}" |
| 36 | include_tasks: "unarchive-{{ transport }}-resource.yml" |
Michal Ptacek | 200ae72 | 2019-03-21 12:32:20 +0000 | [diff] [blame] | 37 | |
| 38 | - name: "Generate flag file after resources are deployed on infra" |
| 39 | file: |
Milan Verespej | ad41e6d | 2019-03-01 14:49:25 +0100 | [diff] [blame] | 40 | path: "{{ resource_destination_directory }}/{{ resource_source_filename }}-uploaded" |
| 41 | state: touch |
| 42 | rescue: |
| 43 | - name: "Get list of destination directory files" |
| 44 | find: |
Samuli Silvius | 29886f0 | 2019-02-19 16:00:37 +0200 | [diff] [blame] | 45 | path: "{{ resource_destination_directory }}" |
Milan Verespej | ad41e6d | 2019-03-01 14:49:25 +0100 | [diff] [blame] | 46 | file_type: any |
| 47 | register: files_after_fail |
| 48 | |
| 49 | - name: "Cleanup the destination directory {{ resource_destination_directory }} on error" |
| 50 | file: |
| 51 | path: "{{ item.path }}" |
Samuli Silvius | 29886f0 | 2019-02-19 16:00:37 +0200 | [diff] [blame] | 52 | state: absent |
Milan Verespej | ad41e6d | 2019-03-01 14:49:25 +0100 | [diff] [blame] | 53 | with_items: "{{ files_after_fail.files | difference(original_files.files) }}" |
| 54 | when: files_after_fail is defined |
| 55 | |
Michal Ptacek | 200ae72 | 2019-03-21 12:32:20 +0000 | [diff] [blame] | 56 | - name: "Report failure of upload operation" |
| 57 | fail: |
Milan Verespej | ad41e6d | 2019-03-01 14:49:25 +0100 | [diff] [blame] | 58 | msg: "Upload of {{ resource_source_filename }} failed" |