|
35 | 35 | # |
36 | 36 | # TODO - files should be owned by www-data |
37 | 37 |
|
38 | | -- block: |
| 38 | + |
| 39 | +- vars: |
| 40 | + # Where the file eventually goes |
| 41 | + dest_path: "{{ dest_base_path }}/{{ item }}" |
| 42 | + |
| 43 | + # Use md5sum to generate the log file name: |
| 44 | + # * Name has short, consistent length. The "to check progress..." message |
| 45 | + # fits within 80 characters on terminal (at least in the current |
| 46 | + # ansible version) in case users have small screens. |
| 47 | + # * If the user mis-copies, it's less likely to do anything destructive. |
| 48 | + log_file: "{{ item | hash('md5') }}.log" |
| 49 | + working_dir: "/library/downloads/maps" |
| 50 | + |
| 51 | + block: |
39 | 52 | - name: "Fetching file size for {{ iiab_map_host_url }}/{{ item }} via .meta4 file" |
40 | 53 | shell: | |
41 | 54 | import sys, xmltodict, requests, os |
|
56 | 69 | size_disp = str(round(size / MiB, 2)) + ' MiB' |
57 | 70 | else: |
58 | 71 | size_disp = str(round(size / GiB, 2)) + ' GiB' |
59 | | - print(' (' + size_disp + ') To check progress, run: "tail {{ working_dir }}/{{ log_file }}"') |
| 72 | + print('(' + size_disp + ') To check download progress, see previous step (above).') |
60 | 73 | args: |
61 | 74 | executable: /usr/bin/python3 |
62 | | - vars: |
63 | | - # Where the file eventually goes |
64 | | - dest_path: "{{ dest_base_path }}/{{ item }}" |
65 | 75 |
|
66 | | - log_file: "{{ item }}.log" |
67 | | - working_dir: "/library/downloads/maps" |
68 | | - register: download_file_size |
| 76 | + # The existence of console output in download_file_details |
| 77 | + # implies that the download should happen. |
| 78 | + register: download_file_details |
| 79 | + |
| 80 | + # Put in some space to make it easier to read by implementers. |
| 81 | + - debug: |
| 82 | + msg: |
| 83 | + - "" |
| 84 | + - "" |
| 85 | + - " To check download progress, run: " |
| 86 | + - "" |
| 87 | + - " tail {{ working_dir }}/{{ log_file }} " |
| 88 | + - "" |
| 89 | + - "" |
| 90 | + # If the file already exists (and thus no download will happen) the above |
| 91 | + # task should exit before any console output. |
| 92 | + when: download_file_details.stdout_lines|length != 0 |
69 | 93 |
|
70 | | - - name: "Download {{ item }}{{ download_file_size.stdout_lines.0 | default(' (done)')}}" |
| 94 | + - name: "Download {{ item }} {{ download_file_details.stdout_lines.0 | default('(done)')}}" |
71 | 95 | # cd to the temp directory so that the aria2c file, data file, and (perhaps |
72 | 96 | # eventually) torrent file all end up there. |
73 | 97 | shell: | |
74 | 98 | set -euo pipefail |
75 | 99 |
|
76 | 100 | cd {{ working_dir }} |
77 | 101 |
|
78 | | - echo "Starting download..." > "{{ log_file }}" |
| 102 | + date > "{{ log_file }}" |
| 103 | + echo "Downloading {{ item }}..." >> "{{ log_file }}" |
| 104 | + echo >> "{{ log_file }}" |
79 | 105 | aria2c \ |
80 | 106 | --connect-timeout="{{ download_timeout }}" \ |
81 | 107 | --log-level=warn \ |
|
97 | 123 | args: |
98 | 124 | executable: /bin/bash |
99 | 125 | creates: "{{ dest_path }}" |
100 | | - vars: |
101 | | - # Where the file eventually goes |
102 | | - dest_path: "{{ dest_base_path }}/{{ item }}" |
103 | 126 |
|
104 | | - log_file: "{{ item }}.log" |
105 | | - working_dir: "/library/downloads/maps" |
106 | 127 | rescue: |
107 | 128 | # We output summaries to a log file for the user's benefit, |
108 | 129 | # but all of the errors necessarily show up there as well. |
|
118 | 139 | echo "aria2c error:" 1>&2 |
119 | 140 | tac "{{ log_file }}" | sed '/'"Download Progress Summary as of"'/q' | tac 1>&2 |
120 | 141 | exit 1 |
121 | | - vars: |
122 | | - log_file: "{{ item }}.log" |
123 | | - working_dir: "/library/downloads/maps" |
|
0 commit comments