mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-26 04:11:25 -07:00
now get_url defaults to module temp dir (#36218)
* now get_url and other modules default to module temp dir also fixed 'bare' exception * allow modules to work with older versions * updated docs per feedback
This commit is contained in:
parent
0bbea9a579
commit
c119d54e4a
7 changed files with 15 additions and 14 deletions
|
@ -49,7 +49,8 @@ options:
|
|||
tmp_dest:
|
||||
description:
|
||||
- Absolute path of where temporary file is downloaded to.
|
||||
- Defaults to C(TMPDIR), C(TEMP) or C(TMP) env variables or a platform specific value.
|
||||
- When run on Ansible 2.5 or greater, path defaults to ansible's remote_tmp setting
|
||||
- When run on Ansible prior to 2.5, it defaults to C(TMPDIR), C(TEMP) or C(TMP) env variables or a platform specific value.
|
||||
- U(https://docs.python.org/2/library/tempfile.html#tempfile.tempdir)
|
||||
version_added: '2.1'
|
||||
force:
|
||||
|
@ -338,18 +339,17 @@ def url_get(module, url, dest, use_proxy, last_mod_time, force, timeout=10, head
|
|||
module.fail_json(msg="%s is a file but should be a directory." % tmp_dest)
|
||||
else:
|
||||
module.fail_json(msg="%s directory does not exist." % tmp_dest)
|
||||
|
||||
fd, tempname = tempfile.mkstemp(dir=tmp_dest)
|
||||
else:
|
||||
fd, tempname = tempfile.mkstemp()
|
||||
tmp_dest = getattr(module, 'tmpdir', None)
|
||||
|
||||
fd, tempname = tempfile.mkstemp(dir=tmp_dest)
|
||||
|
||||
f = os.fdopen(fd, 'wb')
|
||||
try:
|
||||
shutil.copyfileobj(rsp, f)
|
||||
except Exception as e:
|
||||
os.remove(tempname)
|
||||
module.fail_json(msg="failed to create temporary content file: %s" % to_native(e),
|
||||
exception=traceback.format_exc())
|
||||
module.fail_json(msg="failed to create temporary content file: %s" % to_native(e), exception=traceback.format_exc())
|
||||
f.close()
|
||||
rsp.close()
|
||||
return tempname, info
|
||||
|
@ -413,7 +413,7 @@ def main():
|
|||
if module.params['headers']:
|
||||
try:
|
||||
headers = dict(item.split(':', 1) for item in module.params['headers'].split(','))
|
||||
except:
|
||||
except Exception:
|
||||
module.fail_json(msg="The header parameter requires a key:value,key:value syntax to be properly parsed.")
|
||||
else:
|
||||
headers = None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue