ansible/ansible — pull request #6304 by zeroem (2014-03-06 04:29:47+00:00)
Title: Optimize get_url use of the sha256sum

This PR introduces two optimizations and one fix for the get_url module.

The first optimization deals with whether or not we can even generate sha256sums with the given python installation. Previously, this wasn't checked until after the download, wasting time unnecessarily downloading a file we couldn't verify. Now, the `HAS_HASHLIB` check is done before the download allowing the process to short circuit if a sha256sum is provided and the python install is unable to generate one for the downloaded or existing file.

The second optimization deals with using the sha256sum, if provided, to validate an existing file. Previously, if a download was not enforced, there was no way to verify that the local file was actually the same one that was expected to be downloaded. Now, if a sha256sum is provided and downloads are not enforced, get_url will do it's best to calculate the destination file (using a `HEAD` request) without downloading the file and, if it exists, compare the sha256sums.

And finally, there were two module availability checks that were being done and utilizing `module.fail_json` before module had even been instantiated. These have been resolved.