mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
parent
16d522cf2c
commit
55135c0825
1 changed files with 17 additions and 9 deletions
|
@ -2313,25 +2313,33 @@ class AnsibleModule(object):
|
||||||
strings on python3, use encoding=None to turn decoding to text off.
|
strings on python3, use encoding=None to turn decoding to text off.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
shell = False
|
|
||||||
if isinstance(args, list):
|
if isinstance(args, list):
|
||||||
if use_unsafe_shell:
|
if use_unsafe_shell:
|
||||||
args = " ".join([shlex_quote(x) for x in args])
|
args = " ".join([pipes.quote(x) for x in args])
|
||||||
shell = True
|
shell = True
|
||||||
elif isinstance(args, (binary_type, text_type)) and use_unsafe_shell:
|
elif isinstance(args, (binary_type, text_type)) and use_unsafe_shell:
|
||||||
shell = True
|
shell = True
|
||||||
elif isinstance(args, (binary_type, text_type)):
|
elif isinstance(args, (binary_type, text_type)):
|
||||||
# On python2.6 and below, shlex has problems with text type
|
if not use_unsafe_shell:
|
||||||
# On python3, shlex needs a text type.
|
# On python2.6 and below, shlex has problems with text type
|
||||||
if PY2:
|
# On python3, shlex needs a text type.
|
||||||
args = to_bytes(args, errors='surrogate_or_strict')
|
if PY2:
|
||||||
elif PY3:
|
args = to_bytes(args, errors='surrogate_or_strict')
|
||||||
args = to_text(args, errors='surrogateescape')
|
elif PY3:
|
||||||
args = shlex.split(args)
|
args = to_text(args, errors='surrogateescape')
|
||||||
|
args = shlex.split(args)
|
||||||
else:
|
else:
|
||||||
msg = "Argument 'args' to run_command must be list or string"
|
msg = "Argument 'args' to run_command must be list or string"
|
||||||
self.fail_json(rc=257, cmd=args, msg=msg)
|
self.fail_json(rc=257, cmd=args, msg=msg)
|
||||||
|
|
||||||
|
shell = False
|
||||||
|
if use_unsafe_shell:
|
||||||
|
executable = os.environ.get('SHELL')
|
||||||
|
if executable:
|
||||||
|
args = [executable, '-c', args]
|
||||||
|
else:
|
||||||
|
shell = True
|
||||||
|
|
||||||
prompt_re = None
|
prompt_re = None
|
||||||
if prompt_regex:
|
if prompt_regex:
|
||||||
if isinstance(prompt_regex, text_type):
|
if isinstance(prompt_regex, text_type):
|
||||||
|
|
Loading…
Reference in a new issue