Merge pull request #1146 from dhozac/command-escape-args
Properly parse escaped special arguments
This commit is contained in:
commit
b28ee354ca
1 changed files with 6 additions and 5 deletions
11
command
11
command
|
@ -23,6 +23,7 @@ import sys
|
||||||
import datetime
|
import datetime
|
||||||
import traceback
|
import traceback
|
||||||
import shlex
|
import shlex
|
||||||
|
import pipes
|
||||||
import os
|
import os
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
|
@ -139,6 +140,7 @@ class CommandModule(AnsibleModule):
|
||||||
params['shell'] = True
|
params['shell'] = True
|
||||||
|
|
||||||
check_args = shlex.split(args)
|
check_args = shlex.split(args)
|
||||||
|
l_args = []
|
||||||
for x in check_args:
|
for x in check_args:
|
||||||
if x.startswith("creates="):
|
if x.startswith("creates="):
|
||||||
# do not run the command if the line contains creates=filename
|
# do not run the command if the line contains creates=filename
|
||||||
|
@ -154,7 +156,6 @@ class CommandModule(AnsibleModule):
|
||||||
stderr=False,
|
stderr=False,
|
||||||
rc=0
|
rc=0
|
||||||
)
|
)
|
||||||
args = args.replace(x,'')
|
|
||||||
elif x.startswith("removes="):
|
elif x.startswith("removes="):
|
||||||
# do not run the command if the line contains removes=filename
|
# do not run the command if the line contains removes=filename
|
||||||
# and the filename do not exists. This allows idempotence
|
# and the filename do not exists. This allows idempotence
|
||||||
|
@ -169,7 +170,6 @@ class CommandModule(AnsibleModule):
|
||||||
stderr=False,
|
stderr=False,
|
||||||
rc=0
|
rc=0
|
||||||
)
|
)
|
||||||
args = args.replace(x,'')
|
|
||||||
elif x.startswith("chdir="):
|
elif x.startswith("chdir="):
|
||||||
(k,v) = x.split("=", 1)
|
(k,v) = x.split("=", 1)
|
||||||
v = os.path.expanduser(v)
|
v = os.path.expanduser(v)
|
||||||
|
@ -178,8 +178,9 @@ class CommandModule(AnsibleModule):
|
||||||
elif v[0] != '/':
|
elif v[0] != '/':
|
||||||
self.fail_json(msg="the path for 'chdir' argument must be fully qualified")
|
self.fail_json(msg="the path for 'chdir' argument must be fully qualified")
|
||||||
params['chdir'] = v
|
params['chdir'] = v
|
||||||
args = args.replace(x, '')
|
else:
|
||||||
params['args'] = args
|
l_args.append(x)
|
||||||
return (params, args)
|
params['args'] = " ".join([pipes.quote(x) for x in l_args])
|
||||||
|
return (params, params['args'])
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in a new issue