mirror of
https://github.com/ansible/ansible.git
synced 2025-11-30 23:16:08 +07:00
Handle ValueError in run_command when parsing invalid args(shlex.split) (#85945)
This commit is contained in:
3
changelogs/fragments/basic_shlex_split.yml
Normal file
3
changelogs/fragments/basic_shlex_split.yml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
bugfixes:
|
||||||
|
- basic - fail in controlled manner when ``run_command()`` attempts to parse a command with broken syntax passed in as a string (https://github.com/ansible/ansible/issues/85719).
|
||||||
@@ -1969,7 +1969,10 @@ class AnsibleModule(object):
|
|||||||
else:
|
else:
|
||||||
# ensure args are a list
|
# ensure args are a list
|
||||||
if isinstance(args, (bytes, str)):
|
if isinstance(args, (bytes, str)):
|
||||||
args = shlex.split(to_text(args, errors='surrogateescape'))
|
try:
|
||||||
|
args = shlex.split(to_text(args, errors='surrogateescape'))
|
||||||
|
except ValueError as e:
|
||||||
|
self.fail_json(msg="Invalid command syntax in run_command", exception=e)
|
||||||
|
|
||||||
# expand ``~`` in paths, and all environment vars
|
# expand ``~`` in paths, and all environment vars
|
||||||
if expand_user_and_vars:
|
if expand_user_and_vars:
|
||||||
|
|||||||
@@ -198,3 +198,22 @@
|
|||||||
- result.diff.after is defined
|
- result.diff.after is defined
|
||||||
- result.diff.before is defined
|
- result.diff.before is defined
|
||||||
- "result.state == 'file'"
|
- "result.state == 'file'"
|
||||||
|
|
||||||
|
- name: Setup for validate test
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ remote_tmp_dir }}/src_val_syntax"
|
||||||
|
state: directory
|
||||||
|
|
||||||
|
- name: assemble with invalid validation command
|
||||||
|
ansible.builtin.assemble:
|
||||||
|
src: "{{ remote_tmp_dir }}/src_val_syntax"
|
||||||
|
dest: "{{ remote_tmp_dir }}/dest_val_syntax"
|
||||||
|
validate: "echo 'missing %s"
|
||||||
|
register: assemble_syntax_error
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- name: assert assemble failed with ignore_errors
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- assemble_syntax_error.failed
|
||||||
|
- "'Invalid command syntax' in assemble_syntax_error.msg"
|
||||||
Reference in New Issue
Block a user