diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py index 3eace12eeb4..1988857610f 100644 --- a/lib/ansible/module_utils/basic.py +++ b/lib/ansible/module_utils/basic.py @@ -1074,8 +1074,10 @@ class AnsibleModule(object): try: - if cwd: + # make sure we're in the right working directory + if cwd and os.path.isdir(cwd): os.chdir(cwd) + cmd = subprocess.Popen(args, **kwargs) if data: