let chdir support relative path in more modules (#16736)

This commit is contained in:
Gordon Gao 2016-12-22 16:19:50 +08:00 committed by Matt Clay
parent 28b4931e3d
commit d9e1e374b2
2 changed files with 15 additions and 4 deletions

View file

@ -2311,14 +2311,13 @@ class AnsibleModule(object):
stderr=subprocess.PIPE,
)
if cwd and os.path.isdir(cwd):
kwargs['cwd'] = cwd
# store the pwd
prev_dir = os.getcwd()
# make sure we're in the right working directory
if cwd and os.path.isdir(cwd):
cwd = os.path.abspath(os.path.expanduser(cwd))
kwargs['cwd'] = cwd
try:
os.chdir(cwd)
except (OSError, IOError):
@ -2330,7 +2329,6 @@ class AnsibleModule(object):
old_umask = os.umask(umask)
try:
if self._debug:
self.log('Executing: ' + clean_args)
cmd = subprocess.Popen(args, **kwargs)