mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 22:02:50 +00: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:
@@ -107,9 +107,9 @@ from ansible.module_utils.six import b
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
|
||||
def assemble_from_fragments(src_path, delimiter=None, compiled_regexp=None, ignore_hidden=False):
|
||||
def assemble_from_fragments(src_path, delimiter=None, compiled_regexp=None, ignore_hidden=False, tmpdir=None):
|
||||
''' assemble a file from a directory of fragments '''
|
||||
tmpfd, temp_path = tempfile.mkstemp()
|
||||
tmpfd, temp_path = tempfile.mkstemp(dir=tmpdir)
|
||||
tmp = os.fdopen(tmpfd, 'wb')
|
||||
delimit_me = False
|
||||
add_newline = False
|
||||
@@ -204,7 +204,7 @@ def main():
|
||||
if validate and "%s" not in validate:
|
||||
module.fail_json(msg="validate must contain %%s: %s" % validate)
|
||||
|
||||
path = assemble_from_fragments(src, delimiter, compiled_regexp, ignore_hidden)
|
||||
path = assemble_from_fragments(src, delimiter, compiled_regexp, ignore_hidden, getattr(module, 'tmpdir', None))
|
||||
path_hash = module.sha1(path)
|
||||
result['checksum'] = path_hash
|
||||
|
||||
|
||||
@@ -159,7 +159,7 @@ from ansible.module_utils._text import to_bytes
|
||||
|
||||
def write_changes(module, contents, path):
|
||||
|
||||
tmpfd, tmpfile = tempfile.mkstemp()
|
||||
tmpfd, tmpfile = tempfile.mkstemp(dir=getattr(module, 'tmpdir', None))
|
||||
f = os.fdopen(tmpfd, 'wb')
|
||||
f.write(contents)
|
||||
f.close()
|
||||
|
||||
@@ -154,7 +154,7 @@ from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
def write_changes(module, contents, path):
|
||||
|
||||
tmpfd, tmpfile = tempfile.mkstemp()
|
||||
tmpfd, tmpfile = tempfile.mkstemp(dir=getattr(module, 'tmpdir', None))
|
||||
f = os.fdopen(tmpfd, 'wb')
|
||||
f.write(contents)
|
||||
f.close()
|
||||
|
||||
Reference in New Issue
Block a user