Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix docs get_url dest comment. Checksum does not prevent download. #73185

Merged
merged 1 commit into from Oct 7, 2021

Conversation

vbotka
Copy link
Contributor

@vbotka vbotka commented Jan 12, 2021

SUMMARY

Checksum does not prevent download if dest is dir. It's not clear from the documentation.

get_url checksum says:

"Additionally, if a checksum is passed to this parameter, and the file exists under the dest location, the destination_checksum would be calculated, and if checksum equals destination_checksum, the file download would be skipped ..."

get_url dest says:

"If dest is a directory, the file will always be downloaded (regardless of the force option) ..."

The block comparing the checksum is skipped if dest is a directory
https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/get_url.py#L539

if not dest_is_dir and os.path.exists(dest):
ISSUE TYPE
  • Docs Pull Request
COMPONENT NAME

get_url

ADDITIONAL INFORMATION

It's easier to put a directory into dest and let get_url complete the path. Quoting from dest comment:

"If dest is a directory, either the server provided filename or, if none provided, the base name of the URL on the remote server will be used."

Unfortunately, in this case, the checksum of the existing file is not compared and the file is downloaded. A simple solution is to document it:

--- a/lib/ansible/modules/get_url.py
+++ b/lib/ansible/modules/get_url.py
@@ -40,7 +40,8 @@ options:
         none provided, the base name of the URL on the remote server will be
         used. If a directory, C(force) has no effect.
       - If C(dest) is a directory, the file will always be downloaded
-        (regardless of the C(force) option), but replaced only if the contents changed..
+        (regardless of the C(force) and C(checksum) option), but
+        replaced only if the contents changed.
     type: path
     required: true
   tmp_dest:

Verified scenario

  • dest is a directory
  • checksum is present
  1. get_url fetch the file
  2. get_url repeatedly fetch the file (burning resources) without testing the checksum of the already fetched file first

@ansibot ansibot added affects_2.11 core_review In order to be merged, this PR must follow the core review workflow. docs This issue/PR relates to or includes documentation. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. net_tools Net-tools category new_contributor This PR is the first contribution by a new community member. small_patch support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Jan 12, 2021
@bcoca bcoca added the needs_verified This issue needs to be verified/reproduced by maintainer label Jan 14, 2021
@bcoca
Copy link
Member

bcoca commented Jan 14, 2021

doesn't the checksum indicate if the content changed?

@bcoca bcoca added P3 Priority 3 - Approved, No Time Limitation and removed needs_triage Needs a first human triage before being processed. labels Jan 14, 2021
@vbotka
Copy link
Contributor Author

vbotka commented Jan 14, 2021

doesn't the checksum indicate if the content changed?

Content of what?

@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Jan 22, 2021
@ansibot ansibot added the docs_only All changes are to files within the docs/docsite/ directory label Mar 27, 2021
@vbotka
Copy link
Contributor Author

vbotka commented Jul 12, 2021

For the record. The file is unconditionally downloaded but the description of the parameters indicates the possibility of avoiding the download

  • checksum: "... if checksum equals destination_checksum, the file download would be skipped ..."
  • dest: "... If dest is a directory, the file will always be downloaded ..."
  • force: "... If no, the file will only be downloaded if the destination does not exist. Generally should be yes only for small local files. "

It would probably be better to say: "The file will always be downloaded."

Notes:

@samccann
Copy link
Contributor

@bcoca Can you respond here or approve the docs change? thanks.

@vbotka
Copy link
Contributor Author

vbotka commented Oct 5, 2021

@bcoca Can you respond here or approve the docs change? thanks.

The code was updated. Now, it would be easier to test the checksum when dest is a directory before the download.

Copy link
Contributor

@s-hertel s-hertel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is accurate. We can't compare the checksum until we have the destination filename. If dest is a directory the url is fetched to determine the filename (which may come from either the headers or the URL).

@samccann samccann merged commit 8c3e576 into ansible:devel Oct 7, 2021
@samccann
Copy link
Contributor

samccann commented Oct 7, 2021

Thanks @vbotka for the Ansible docs fix!

@ansible ansible locked and limited conversation to collaborators Nov 4, 2021
@sivel sivel removed the needs_verified This issue needs to be verified/reproduced by maintainer label Feb 3, 2022
@vbotka vbotka deleted the fix_get_url_dest_comment branch February 3, 2022 23:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.11 core_review In order to be merged, this PR must follow the core review workflow. docs_only All changes are to files within the docs/docsite/ directory docs This issue/PR relates to or includes documentation. module This issue/PR relates to a module. net_tools Net-tools category new_contributor This PR is the first contribution by a new community member. P3 Priority 3 - Approved, No Time Limitation small_patch stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants