[get_url] skip checksum during --check (#66700)

Fix get_url failure in check mode (--check) when using the checksum
format <algorithm>:<url>.

Regression introduced in (#20532)

Fixes: #61369
This commit is contained in:
pva 2020-12-22 19:04:42 +03:00 committed by GitHub
parent aa56a2ff6a
commit 42bc03f0f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 6 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- get_url - skip checksum during ``--check`` (https://github.com/ansible/ansible/issues/61369).

View file

@ -358,16 +358,12 @@ def url_filename(url):
return fn
def url_get(module, url, dest, use_proxy, last_mod_time, force, timeout=10, headers=None, tmp_dest=''):
def url_get(module, url, dest, use_proxy, last_mod_time, force, timeout=10, headers=None, tmp_dest='', method='GET'):
"""
Download data from the url and store in a temporary file.
Return (tempfile, info about the request)
"""
if module.check_mode:
method = 'HEAD'
else:
method = 'GET'
start = datetime.datetime.utcnow()
rsp, info = fetch_url(module, url, use_proxy=use_proxy, force=force, last_mod_time=last_mod_time, timeout=timeout, headers=headers, method=method)
@ -573,7 +569,8 @@ def main():
# download to tmpsrc
start = datetime.datetime.utcnow()
tmpsrc, info = url_get(module, url, dest, use_proxy, last_mod_time, force, timeout, headers, tmp_dest)
method = 'HEAD' if module.check_mode else 'GET'
tmpsrc, info = url_get(module, url, dest, use_proxy, last_mod_time, force, timeout, headers, tmp_dest, method)
result['elapsed'] = (datetime.datetime.utcnow() - start).seconds
result['src'] = tmpsrc

View file

@ -382,6 +382,14 @@
port: '{{ http_port }}'
state: started
- name: download src with sha1 checksum url in check mode
get_url:
url: 'http://localhost:{{ http_port }}/27617.txt'
dest: '{{ remote_tmp_dir }}'
checksum: 'sha1:http://localhost:{{ http_port }}/sha1sum.txt'
register: result_sha1_check_mode
check_mode: True
- name: download src with sha1 checksum url
get_url:
url: 'http://localhost:{{ http_port }}/27617.txt'
@ -473,6 +481,7 @@
- name: Assert that the file was downloaded
assert:
that:
- result_sha1_check_mode is changed
- result_sha1 is changed
- result_sha256 is changed
- result_sha256_with_dot is changed