summaryrefslogtreecommitdiff
path: root/lib/ansible/module_utils
diff options
context:
space:
mode:
authorToshio Kuratomi <a.badger@gmail.com>2018-02-15 09:01:02 -0800
committerGitHub <noreply@github.com>2018-02-15 09:01:02 -0800
commit06f73ad578d840c7ea5875b7cd4ffd08e2d9d0e8 (patch)
tree721a0ad5a9a1fa03229ad19a8dcd10dbb54a10b6 /lib/ansible/module_utils
parent2678508d427618c6d50f447f41689a1b31d72b86 (diff)
downloadansible-06f73ad578d840c7ea5875b7cd4ffd08e2d9d0e8.tar.gz
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
Diffstat (limited to 'lib/ansible/module_utils')
-rw-r--r--lib/ansible/module_utils/basic.py8
-rw-r--r--lib/ansible/module_utils/urls.py5
2 files changed, 8 insertions, 5 deletions
diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py
index 3a8fa29249..a7cf24ab70 100644
--- a/lib/ansible/module_utils/basic.py
+++ b/lib/ansible/module_utils/basic.py
@@ -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)
diff --git a/lib/ansible/module_utils/urls.py b/lib/ansible/module_utils/urls.py
index e0347035c8..d4de90edb1 100644
--- a/lib/ansible/module_utils/urls.py
+++ b/lib/ansible/module_utils/urls.py
@@ -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