From a9f6cc1d2c6e5de4819483580cde42d40056bb67 Mon Sep 17 00:00:00 2001 From: Norman Ziegner Date: Thu, 30 Mar 2023 13:03:31 +0200 Subject: [PATCH] get_url - support tabs in checksum file Signed-off-by: Norman Ziegner --- lib/ansible/modules/get_url.py | 2 +- .../targets/get_url/tasks/main.yml | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/get_url.py b/lib/ansible/modules/get_url.py index 2d85d4da363..69ccb3f3bb0 100644 --- a/lib/ansible/modules/get_url.py +++ b/lib/ansible/modules/get_url.py @@ -548,7 +548,7 @@ def main(): # checksum filename for line in lines: # Split by one whitespace to keep the leading type char ' ' (whitespace) for text and '*' for binary - parts = line.split(" ", 1) + parts = re.split('[ \t]', line, 1) if len(parts) == 2: # Remove the leading type char, we expect if parts[1].startswith((" ", "*",)): diff --git a/test/integration/targets/get_url/tasks/main.yml b/test/integration/targets/get_url/tasks/main.yml index c26cc08b188..a76baab28ba 100644 --- a/test/integration/targets/get_url/tasks/main.yml +++ b/test/integration/targets/get_url/tasks/main.yml @@ -358,6 +358,23 @@ 30949cc401e30ac494d695ab8764a9f76aae17c5d73c67f65e9b558f47eff892 not_target1.txt d0dbfc1945bc83bf6606b770e442035f2c4e15c886ee0c22fb3901ba19900b5b not_target2.txt +- name: create sha256 checksum file of src with tab character in it + copy: + dest: '{{ files_dir }}/sha256sum_with_tab.txt' + content: " + b1b6ce5073c8fac263a8fc5edfffdbd5dec1980c784e09c5bc69f8fb6056f006.\t27617.txt\n + b1b6ce5073c8fac263a8fc5edfffdbd5dec1980c784e09c5bc69f8fb6056f006.\t71420.txt\n + 30949cc401e30ac494d695ab8764a9f76aae17c5d73c67f65e9b558f47eff892\tnot_target1.txt\n + d0dbfc1945bc83bf6606b770e442035f2c4e15c886ee0c22fb3901ba19900b5b\tnot_target2.txt\n" + +- name: Display sha256sum_with_tab.txt contents + command: "cat {{ files_dir }}/sha256sum_with_tab.txt" + register: command_output + +- name: Print to console + debug: + msg: "{{command_output.stdout}}" + - name: create sha256 checksum file of src with a dot leading path copy: dest: '{{ files_dir }}/sha256sum_with_dot.txt' @@ -430,6 +447,17 @@ path: "{{ remote_tmp_dir }}/27617.txt" register: stat_result_sha256 +- name: download src with sha256 checksum url with tab + get_url: + url: 'http://localhost:{{ http_port }}/27617.txt' + dest: '{{ remote_tmp_dir }}/27617sha256_with_tab.txt' + checksum: 'sha256:http://localhost:{{ http_port }}/sha256sum_with_tab.txt' + register: result_sha256_with_tab + +- stat: + path: "{{ remote_tmp_dir }}/27617sha256_with_tab.txt" + register: stat_result_sha256_with_tab + - name: download src with sha256 checksum url with dot leading paths get_url: url: 'http://localhost:{{ http_port }}/27617.txt' @@ -485,6 +513,17 @@ path: "{{ remote_tmp_dir }}/71420.txt" register: stat_result_sha256_71420 +- name: download 71420.txt with sha256 checksum url with tab + get_url: + url: 'http://localhost:{{ http_port }}/71420.txt' + dest: '{{ remote_tmp_dir }}/71420sha256_with_tab.txt' + checksum: 'sha256:http://localhost:{{ http_port }}/sha256sum_with_tab.txt' + register: result_sha256_with_tab_71420 + +- stat: + path: "{{ remote_tmp_dir }}/71420sha256_with_tab.txt" + register: stat_result_sha256_with_tab_71420 + - name: download 71420.txt with sha256 checksum url with dot leading paths get_url: url: 'http://localhost:{{ http_port }}/71420.txt' @@ -536,22 +575,26 @@ - result_sha1_check_mode is changed - result_sha256 is changed - result_sha256_with_dot is changed + - result_sha256_with_tab is changed - result_sha256_with_asterisk is changed - result_sha256_with_file_scheme is changed - "stat_result_sha1.stat.exists == true" - "stat_result_sha256.stat.exists == true" - "stat_result_sha256_with_dot.stat.exists == true" + - "stat_result_sha256_with_tab.stat.exists == true" - "stat_result_sha256_with_asterisk.stat.exists == true" - "stat_result_sha256_with_file_scheme.stat.exists == true" - result_sha1_71420 is changed - result_sha256_71420 is changed - result_sha256_with_dot_71420 is changed + - result_sha256_with_tab_71420 is changed - result_sha256_with_asterisk_71420 is changed - result_sha256_checksum_only is changed - result_sha256_with_file_scheme_71420 is changed - "stat_result_sha1_71420.stat.exists == true" - "stat_result_sha256_71420.stat.exists == true" - "stat_result_sha256_with_dot_71420.stat.exists == true" + - "stat_result_sha256_with_tab_71420.stat.exists == true" - "stat_result_sha256_with_asterisk_71420.stat.exists == true" - "stat_result_sha256_with_file_scheme_71420.stat.exists == true" - "stat_result_sha256_checksum_only.stat.exists == true"