Skip to content

Commit cafe066

Browse files
committed
add default deduplicate to download role
1 parent 8ba6820 commit cafe066

6 files changed

Lines changed: 26 additions & 12 deletions

File tree

roles/sap_software_download/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,11 +323,14 @@ If set to `false`, the role will execute dry run to validate S-User credentials.
323323

324324
### sap_software_download_deduplicate
325325
- _Type:_ `string`<br>
326+
- _Default:_ `last`<br>
326327

327328
Specifies how to handle duplicate file results when using `sap_software_download_files`.<br>
328329
If multiple files with the same name are found, this setting determines which one to download.<br>
330+
329331
- `first`: Download the first file found<br>
330332
- `last`: Download the last file found.<br>
333+
- `''`: No deduplication, will cause an error if multiple files with the same name are found.<br>
331334

332335
### sap_software_download_validate_checksum
333336
- _Type:_ `bool`<br>

roles/sap_software_download/defaults/main.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,10 @@ sap_software_download_ignore_validate_credentials: false
8585

8686
# Specifies how to handle duplicate file results when using `sap_software_download_files`.
8787
# If multiple files with the same name are found, this setting determines which one to download.
88-
# `first`: Download the first file found.
89-
# `last`: Download the last file found.
90-
# sap_software_download_deduplicate: first
88+
# - `first`: Download the first file found.
89+
# - `last`: Download the last file found.
90+
# - `''`: No deduplication, will cause an error if multiple files with the same name are found.
91+
sap_software_download_deduplicate: last
9192

9293
# Enables checksum validation of existing files present in `sap_software_download_directory`.
9394
# This does not affect automatic checksum validation of downloaded files.

roles/sap_software_download/meta/argument_spec.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ argument_specs:
157157
sap_software_download_deduplicate:
158158
type: str
159159
required: false
160-
default: "first"
161-
choices: ["first", "last"]
160+
default: "last"
161+
choices: ["first", "last", ""]
162162
description:
163163
- Specifies how to handle duplicate file results when using `sap_software_download_files`.
164164
- If multiple files with the same name are found, this setting determines which one to download.

roles/sap_software_download/tasks/download_files.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
search_query: "{{ item }}"
99
dest: "{{ sap_software_download_directory }}"
1010
search_alternatives: "{{ sap_software_download_find_alternatives | d(true) }}"
11-
deduplicate: "{{ sap_software_download_deduplicate | d('') }}"
11+
deduplicate: "{{ sap_software_download_deduplicate }}"
1212
validate_checksum: "{{ sap_software_download_validate_checksum | d(false) }}"
1313
# Loop condition acts as when conditional
1414
loop: "{{ sap_software_download_files if sap_software_download_use_venv | d(true) else [] }}"
@@ -31,7 +31,7 @@
3131
search_query: "{{ item }}"
3232
dest: "{{ sap_software_download_directory }}"
3333
search_alternatives: "{{ sap_software_download_find_alternatives | d(true) }}"
34-
deduplicate: "{{ sap_software_download_deduplicate | d('') }}"
34+
deduplicate: "{{ sap_software_download_deduplicate }}"
3535
validate_checksum: "{{ sap_software_download_validate_checksum | d(false) }}"
3636
# Loop condition acts as when conditional
3737
loop: "{{ sap_software_download_files if not sap_software_download_use_venv | d(true) else [] }}"
@@ -52,8 +52,16 @@
5252
ansible.builtin.fail:
5353
msg: |
5454
Download failed for following files: {{ __failed_items | map(attribute='item') | list | join(', ') }}
55+
56+
{% if not sap_software_download_find_alternatives | d(false) %}
5557
Either set `sap_software_download_find_alternatives` to `true` to search for alternative files
5658
or ignore this error with `sap_software_download_ignore_file_not_found` set to `true`.
59+
60+
{% endif %}
61+
{% for failed_item in __failed_items %}
62+
{{ failed_item.item }}: {{ failed_item.msg | d('') }}
63+
64+
{% endfor %}
5765
vars:
5866
__failed_items: "{{ __sap_software_download_files_results.results
5967
| selectattr('failed', 'defined') | selectattr('failed', 'true') }}"

roles/sap_software_download/tasks/pre_steps/01_include_variables.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,10 @@
116116
- name: "Pre-Steps - Verify variable: sap_software_download_deduplicate"
117117
ansible.builtin.assert:
118118
that:
119-
- sap_software_download_deduplicate in ['first', 'last']
119+
- sap_software_download_deduplicate is defined
120+
- sap_software_download_deduplicate is string
121+
- sap_software_download_deduplicate in ['first', 'last', '']
120122
fail_msg: |
121123
Enter valid option for `sap_software_download_deduplicate` variable.
122-
Options: first, last
123-
when: sap_software_download_deduplicate is defined
124+
Options: first, last or empty string ''.
125+
NOTE: Empty string will cause an error if multiple files with the same name are found.

roles/sap_software_download/tasks/pre_steps/05_validate_relations.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
search_query: "{{ item }}"
1313
dest: "{{ sap_software_download_directory }}"
1414
search_alternatives: "{{ sap_software_download_find_alternatives | d(true) }}"
15-
deduplicate: "{{ sap_software_download_deduplicate | d('') }}"
15+
deduplicate: "{{ sap_software_download_deduplicate }}"
1616
dry_run: true
1717
# Loop condition acts as when conditional
1818
loop: "{{ sap_software_download_files if sap_software_download_use_venv | d(true) else [] }}"
@@ -37,7 +37,7 @@
3737
search_query: "{{ item }}"
3838
dest: "{{ sap_software_download_directory }}"
3939
search_alternatives: "{{ sap_software_download_find_alternatives | d(true) }}"
40-
deduplicate: "{{ sap_software_download_deduplicate | d('') }}"
40+
deduplicate: "{{ sap_software_download_deduplicate }}"
4141
dry_run: true
4242
# Loop condition acts as when conditional
4343
loop: "{{ sap_software_download_files if not sap_software_download_use_venv | d(true) else [] }}"

0 commit comments

Comments
 (0)