Debian Codegraph @

test/integration/targets/blockinfile/tasks/create_dir.yml

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