slurp - handle error when path is a directory (#74930)
This commit is contained in:
parent
36287e9810
commit
0a5cc80ce2
4 changed files with 15 additions and 8 deletions
2
changelogs/fragments/slurp-handle-error-with-dir.yml
Normal file
2
changelogs/fragments/slurp-handle-error-with-dir.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- slurp - handle error when ``path`` is a directory and not a file (https://github.com/ansible/ansible/pull/74930).
|
|
@ -81,6 +81,7 @@ import errno
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
from ansible.module_utils.common.text.converters import to_native
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -101,6 +102,10 @@ def main():
|
||||||
module.fail_json(msg="file not found: %s" % source)
|
module.fail_json(msg="file not found: %s" % source)
|
||||||
elif e.errno == errno.EACCES:
|
elif e.errno == errno.EACCES:
|
||||||
module.fail_json(msg="file is not readable: %s" % source)
|
module.fail_json(msg="file is not readable: %s" % source)
|
||||||
|
elif e.errno == errno.EISDIR:
|
||||||
|
module.fail_json(msg="source is a directory and must be a file: %s" % source)
|
||||||
|
else:
|
||||||
|
module.fail_json(msg="unable to slurp file: %s" % to_native(e, errors='surrogate_then_replace'))
|
||||||
|
|
||||||
data = base64.b64encode(source_content)
|
data = base64.b64encode(source_content)
|
||||||
|
|
||||||
|
|
|
@ -81,9 +81,9 @@
|
||||||
- name: check slurp directory result
|
- name: check slurp directory result
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- "slurp_dir is failed"
|
- slurp_dir is failed
|
||||||
- "slurp_dir.msg"
|
- slurp_dir.msg is search('source is a directory and must be a file')
|
||||||
- "slurp_dir is not changed"
|
- slurp_dir is not changed
|
||||||
|
|
||||||
- name: test slurp with missing argument
|
- name: test slurp with missing argument
|
||||||
action: slurp
|
action: slurp
|
||||||
|
|
|
@ -8,13 +8,13 @@
|
||||||
- name: create unreadable file
|
- name: create unreadable file
|
||||||
copy:
|
copy:
|
||||||
content: "Hello, World!"
|
content: "Hello, World!"
|
||||||
dest: /tmp/qux.txt
|
dest: "{{ output_dir }}/qux.txt"
|
||||||
mode: 0600
|
mode: '0600'
|
||||||
owner: root
|
owner: root
|
||||||
|
|
||||||
- name: test slurp unreadable file
|
- name: test slurp unreadable file
|
||||||
slurp:
|
slurp:
|
||||||
src: '/tmp/qux.txt'
|
src: "{{ output_dir }}/qux.txt"
|
||||||
register: slurp_unreadable_file
|
register: slurp_unreadable_file
|
||||||
become: true
|
become: true
|
||||||
become_user: "{{ become_test_user }}"
|
become_user: "{{ become_test_user }}"
|
||||||
|
@ -30,14 +30,14 @@
|
||||||
|
|
||||||
- name: create unreadable directory
|
- name: create unreadable directory
|
||||||
file:
|
file:
|
||||||
path: /tmp/test_data
|
path: "{{ output_dir }}/test_data"
|
||||||
state: directory
|
state: directory
|
||||||
mode: 0700
|
mode: 0700
|
||||||
owner: root
|
owner: root
|
||||||
|
|
||||||
- name: test slurp unreadable directory
|
- name: test slurp unreadable directory
|
||||||
slurp:
|
slurp:
|
||||||
src: /tmp/test_data
|
src: "{{ output_dir }}/test_data"
|
||||||
register: slurp_unreadable_dir
|
register: slurp_unreadable_dir
|
||||||
become: true
|
become: true
|
||||||
become_user: "{{ become_test_user }}"
|
become_user: "{{ become_test_user }}"
|
||||||
|
|
Loading…
Reference in a new issue