Debian Codegraph @

test/integration/targets/module_utils/library/test_cwd_unreadable.py

raw
1 #!/usr/bin/python
2 from __future__ import annotations
3
4 import os
5
6 from ansible.module_utils.basic import AnsibleModule
7
8
9 def main():
10 # This module verifies that AnsibleModule works when cwd exists but is unreadable.
11 # This situation can occur when running tasks as an unprivileged user.
12
13 try:
14 cwd = os.getcwd()
15 except OSError:
16 # Compensate for macOS being unable to access cwd as an unprivileged user.
17 # This test is a no-op in this case.
18 # Testing for os.getcwd() failures is handled by the test_cwd_missing module.
19 cwd = '/'
20 os.chdir(cwd)
21
22 module = AnsibleModule(argument_spec=dict())
23 module.exit_json(before=cwd, after=os.getcwd())
24
25
26 if __name__ == '__main__':
27 main()