mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-23 19:01:26 -07:00
Reset the current directory after running subprocess.Popen
This commit is contained in:
parent
69ff355726
commit
a348f67238
1 changed files with 13 additions and 4 deletions
|
@ -1074,12 +1074,17 @@ class AnsibleModule(object):
|
||||||
if cwd and os.path.isdir(cwd):
|
if cwd and os.path.isdir(cwd):
|
||||||
kwargs['cwd'] = cwd
|
kwargs['cwd'] = cwd
|
||||||
|
|
||||||
|
# store the pwd
|
||||||
|
prev_dir = os.getcwd()
|
||||||
|
|
||||||
try:
|
|
||||||
# make sure we're in the right working directory
|
# make sure we're in the right working directory
|
||||||
if cwd and os.path.isdir(cwd):
|
if cwd and os.path.isdir(cwd):
|
||||||
|
try:
|
||||||
os.chdir(cwd)
|
os.chdir(cwd)
|
||||||
|
except (OSError, IOError), e:
|
||||||
|
self.fail_json(rc=e.errno, msg="Could not open %s , %s" % (cwd, str(e)))
|
||||||
|
|
||||||
|
try:
|
||||||
cmd = subprocess.Popen(args, **kwargs)
|
cmd = subprocess.Popen(args, **kwargs)
|
||||||
|
|
||||||
if data:
|
if data:
|
||||||
|
@ -1094,6 +1099,10 @@ class AnsibleModule(object):
|
||||||
if rc != 0 and check_rc:
|
if rc != 0 and check_rc:
|
||||||
msg = err.rstrip()
|
msg = err.rstrip()
|
||||||
self.fail_json(cmd=clean_args, rc=rc, stdout=out, stderr=err, msg=msg)
|
self.fail_json(cmd=clean_args, rc=rc, stdout=out, stderr=err, msg=msg)
|
||||||
|
|
||||||
|
# reset the pwd
|
||||||
|
os.chdir(prev_dir)
|
||||||
|
|
||||||
return (rc, out, err)
|
return (rc, out, err)
|
||||||
|
|
||||||
def append_to_file(self, filename, str):
|
def append_to_file(self, filename, str):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue