diff options
author | Felix Fontein <felix@fontein.de> | 2023-09-12 21:46:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-12 21:46:44 +0200 |
commit | 7f0baabbe0e62074e86e4317653a37e46b0410b0 (patch) | |
tree | 74c0bdc90b044fef7f56285312ca513245492161 /test/integration/targets/blockinfile | |
parent | sanity: update requirements (#81680) (diff) | |
download | ansible-7f0baabbe0e62074e86e4317653a37e46b0410b0.tar.xz ansible-7f0baabbe0e62074e86e4317653a37e46b0410b0.zip |
blockinfile: avoid crash on Python 3 when creating directory fails (#81662)
* Avoid crash on Python 3.
* Add a test for the crash on Python 3
Diffstat (limited to 'test/integration/targets/blockinfile')
-rw-r--r-- | test/integration/targets/blockinfile/tasks/create_dir.yml | 29 | ||||
-rw-r--r-- | test/integration/targets/blockinfile/tasks/main.yml | 1 |
2 files changed, 30 insertions, 0 deletions
diff --git a/test/integration/targets/blockinfile/tasks/create_dir.yml b/test/integration/targets/blockinfile/tasks/create_dir.yml new file mode 100644 index 0000000000..a16ada5e49 --- /dev/null +++ b/test/integration/targets/blockinfile/tasks/create_dir.yml @@ -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'" diff --git a/test/integration/targets/blockinfile/tasks/main.yml b/test/integration/targets/blockinfile/tasks/main.yml index b7f5161c8a..f26cb165e9 100644 --- a/test/integration/targets/blockinfile/tasks/main.yml +++ b/test/integration/targets/blockinfile/tasks/main.yml @@ -31,6 +31,7 @@ - import_tasks: add_block_to_existing_file.yml - import_tasks: create_file.yml +- import_tasks: create_dir.yml - import_tasks: preserve_line_endings.yml - import_tasks: block_without_trailing_newline.yml - import_tasks: file_without_trailing_newline.yml |