mirror of https://github.com/ansible/ansible.git
blockinfile: avoid crash on Python 3 when creating directory fails (#81662)
* Avoid crash on Python 3. * Add a test for the crash on Python 3pull/81586/head
parent
3b608f97b1
commit
7f0baabbe0
@ -0,0 +1,2 @@
|
||||
bugfixes:
|
||||
- "blockinfile - avoid crash with Python 3 if creating the directory fails when ``create=true`` (https://github.com/ansible/ansible/pull/81662)."
|
||||
@ -0,0 +1,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'"
|
||||
Loading…
Reference in New Issue