Debian Codegraph @

test/integration/targets/module_utils/module_utils_basic_setcwd.yml

raw
1 - hosts: testhost
2 gather_facts: no
3 tasks:
4 - name: make sure the test user is available
5 include_role:
6 name: setup_test_user
7 public: yes
8
9 - name: verify AnsibleModule works when cwd is missing
10 test_cwd_missing:
11 register: missing
12
13 - name: record the mode of the connection user's home directory
14 stat:
15 path: "~"
16 vars:
17 ansible_become: no
18 register: connection_user_home
19
20 - name: limit access to the connection user's home directory
21 file:
22 state: directory
23 path: "{{ connection_user_home.stat.path }}"
24 mode: "0700"
25 vars:
26 ansible_become: no
27
28 - block:
29 - name: verify AnsibleModule works when cwd is unreadable
30 test_cwd_unreadable:
31 register: unreadable
32 vars: &test_user_become
33 ansible_become: yes
34 ansible_become_user: "{{ test_user_name }}" # root can read cwd regardless of permissions, so a non-root user is required here
35 ansible_become_password: "{{ test_user_plaintext_password }}"
36 always:
37 - name: restore access to the connection user's home directory
38 file:
39 state: directory
40 path: "{{ connection_user_home.stat.path }}"
41 mode: "{{ connection_user_home.stat.mode }}"
42 vars:
43 ansible_become: no
44
45 - name: get real path of home directory of the unprivileged user
46 raw: "{{ ansible_python_interpreter }} -c 'import os.path; print(os.path.realpath(os.path.expanduser(\"~\")))'"
47 register: home
48 vars: *test_user_become
49
50 - name: verify AnsibleModule was able to adjust cwd as expected
51 assert:
52 that:
53 - missing.before != missing.after
54 - unreadable.before != unreadable.after or unreadable.before == '/' or unreadable.before == home.stdout.strip() # allow / and $HOME fallback on macOS when using an unprivileged user