You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ansible/test/integration/targets/blockinfile/tasks/create_dir.yml

30 lines
808 B
YAML

- 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'"