Move splitter to module_utils so modules can use it and fix command arg splitting
Fixes #8338
This commit is contained in:
parent
7cd6d6fb89
commit
0963d4aee4
1 changed files with 3 additions and 6 deletions
|
@ -186,6 +186,7 @@ def main():
|
||||||
|
|
||||||
# import module snippets
|
# import module snippets
|
||||||
from ansible.module_utils.basic import *
|
from ansible.module_utils.basic import *
|
||||||
|
from ansible.module_utils.splitter import *
|
||||||
|
|
||||||
# only the command module should ever need to do this
|
# only the command module should ever need to do this
|
||||||
# everything else should be simple key=value
|
# everything else should be simple key=value
|
||||||
|
@ -211,18 +212,14 @@ class CommandModule(AnsibleModule):
|
||||||
args = args.replace("#USE_SHELL", "")
|
args = args.replace("#USE_SHELL", "")
|
||||||
params['shell'] = True
|
params['shell'] = True
|
||||||
|
|
||||||
# use shlex to split up the args, while being careful to preserve
|
items = split_args(args)
|
||||||
# single quotes so they're not removed accidentally
|
|
||||||
lexer = shlex.shlex(args)
|
|
||||||
lexer.whitespace = '\t '
|
|
||||||
lexer.whitespace_split = True
|
|
||||||
items = list(lexer)
|
|
||||||
|
|
||||||
for x in items:
|
for x in items:
|
||||||
quoted = x.startswith('"') and x.endswith('"') or x.startswith("'") and x.endswith("'")
|
quoted = x.startswith('"') and x.endswith('"') or x.startswith("'") and x.endswith("'")
|
||||||
if '=' in x and not quoted:
|
if '=' in x and not quoted:
|
||||||
# check to see if this is a special parameter for the command
|
# check to see if this is a special parameter for the command
|
||||||
k, v = x.split('=', 1)
|
k, v = x.split('=', 1)
|
||||||
|
v = unquote(v)
|
||||||
# because we're not breaking out quotes in the shlex split
|
# because we're not breaking out quotes in the shlex split
|
||||||
# above, the value of the k=v pair may still be quoted. If
|
# above, the value of the k=v pair may still be quoted. If
|
||||||
# so, remove them.
|
# so, remove them.
|
||||||
|
|
Loading…
Reference in a new issue