diff --git a/changelogs/fragments/69201-fix-cwd-sanity-requirements.yml b/changelogs/fragments/69201-fix-cwd-sanity-requirements.yml new file mode 100644 index 00000000000..9cdacf7bb10 --- /dev/null +++ b/changelogs/fragments/69201-fix-cwd-sanity-requirements.yml @@ -0,0 +1,4 @@ +bugfixes: +- module_utils - When checking that it is possible to cd in current working + directory before running a module, ansible now also checks that the directory + is searchable (+x). diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py index a4d211f4d40..ebc82b60dae 100644 --- a/lib/ansible/module_utils/basic.py +++ b/lib/ansible/module_utils/basic.py @@ -1932,7 +1932,7 @@ class AnsibleModule(object): def _set_cwd(self): try: cwd = os.getcwd() - if not os.access(cwd, os.F_OK | os.R_OK): + if not os.access(cwd, os.F_OK | os.R_OK | os.X_OK): raise Exception() return cwd except Exception: @@ -1940,7 +1940,7 @@ class AnsibleModule(object): # Try and move to a neutral location to prevent errors for cwd in [self.tmpdir, os.path.expandvars('$HOME'), tempfile.gettempdir()]: try: - if os.access(cwd, os.F_OK | os.R_OK): + if os.access(cwd, os.F_OK | os.R_OK | os.X_OK): os.chdir(cwd) return cwd except Exception: