Normalize usage of temp and tmp on tmp (#36221)

* Normalize usage of temp and tmp on tmp
* Rename system_tmps system_tmpdirs
* Add ANSIBLE_REMOTE_TMP spelling of environment variables
This commit is contained in:
Toshio Kuratomi
2018-02-15 09:01:02 -08:00
committed by GitHub
parent 2678508d42
commit 06f73ad578
22 changed files with 99 additions and 92 deletions

View File

@@ -47,7 +47,7 @@ PASS_VARS = {
'shell_executable': '_shell',
'socket': '_socket_path',
'syslog_facility': '_syslog_facility',
'tempdir': 'tempdir',
'tmpdir': 'tmpdir',
'verbosity': '_verbosity',
'version': 'ansible_version',
}
@@ -2199,7 +2199,7 @@ class AnsibleModule(object):
except:
# we don't have access to the cwd, probably because of sudo.
# Try and move to a neutral location to prevent errors
for cwd in [self.tempdir, os.path.expandvars('$HOME'), tempfile.gettempdir()]:
for cwd in [self.tmpdir, os.path.expandvars('$HOME'), tempfile.gettempdir()]:
try:
if os.access(cwd, os.F_OK | os.R_OK):
os.chdir(cwd)
@@ -2511,7 +2511,7 @@ class AnsibleModule(object):
# would end in something like:
# file = _os.path.join(dir, pre + name + suf)
# TypeError: can't concat bytes to str
error_msg = ('Failed creating temp file for atomic move. This usually happens when using Python3 less than Python3.5. '
error_msg = ('Failed creating tmp file for atomic move. This usually happens when using Python3 less than Python3.5. '
'Please use Python2.x or Python3.5 or greater.')
finally:
if error_msg:
@@ -2531,7 +2531,7 @@ class AnsibleModule(object):
try:
shutil.move(b_src, b_tmp_dest_name)
except OSError:
# cleanup will happen by 'rm' of tempdir
# cleanup will happen by 'rm' of tmpdir
# copy2 will preserve some metadata
shutil.copy2(b_src, b_tmp_dest_name)

View File

@@ -988,7 +988,8 @@ def fetch_url(module, url, data=None, headers=None, method=None,
module.fail_json(msg='urlparse is not installed')
# ensure we use proper tempdir
tempfile.tempdir = module.tempdir
old_tempdir = tempfile.tempdir
tempfile.tempdir = module.tmpdir
# Get validate_certs from the module params
validate_certs = module.params.get('validate_certs', True)
@@ -1052,5 +1053,7 @@ def fetch_url(module, url, data=None, headers=None, method=None,
except Exception as e:
info.update(dict(msg="An unknown error occurred: %s" % to_native(e), status=-1),
exception=traceback.format_exc())
finally:
tempfile.tempdir = old_tempdir
return r, info