blob: a16ada5e49a89ad599e86554b66ea77d5c52d672 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
- name: Set up a directory to test module error handling
file:
path: "{{ remote_tmp_dir_test }}/unreadable"
state: directory
mode: "000"
- name: Create a directory and file with blockinfile
blockinfile:
path: "{{ remote_tmp_dir_test }}/unreadable/createme/file.txt"
block: |
line 1
line 2
state: present
create: yes
register: permissions_error
ignore_errors: yes
- name: assert the error looks right
assert:
that:
- permissions_error.msg.startswith('Error creating')
when: "ansible_user_id != 'root'"
- name: otherwise (root) assert the directory and file exists
stat:
path: "{{ remote_tmp_dir_test }}/unreadable/createme/file.txt"
register: path_created
failed_when: path_created.exists is false
when: "ansible_user_id == 'root'"
|