Module basic.py to create parent dirs of tmpdir if needed (#40201)

* Module basic.py to create parent dirs of tmpdir if needed

* Added warning to dir creation

* Assert if make_dirs was called or not in unit tests
This commit is contained in:
Jordan Borean 2018-05-17 09:52:46 +10:00 committed by GitHub
parent 5df370243d
commit 5c39c3b2d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 2 deletions

View file

@ -938,6 +938,14 @@ class AnsibleModule(object):
# clean it up once finished.
if self._tmpdir is None:
basedir = os.path.expanduser(os.path.expandvars(self._remote_tmp))
if not os.path.exists(basedir):
self.warn("Module remote_tmp %s did not exist and was created "
"with a mode of 0700, this may cause issues when "
"running as another user. To avoid this, create the "
"remote_tmp dir with the correct permissions "
"manually" % basedir)
os.makedirs(basedir, mode=0o700)
basefile = "ansible-moduletmp-%s-" % time.time()
tmpdir = tempfile.mkdtemp(prefix=basefile, dir=basedir)
if not self._keep_remote_files: