Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
46b47a55
Commit
46b47a55
authored
Jul 23, 2014
by
James Cammarata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes for module param counting and additional shell quoting issues
parent
8933763b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
16 deletions
+24
-16
lib/ansible/runner/__init__.py
+14
-11
library/commands/command
+10
-5
No files found.
lib/ansible/runner/__init__.py
View file @
46b47a55
...
...
@@ -395,7 +395,7 @@ class Runner(object):
return
actual_user
def
_count_module_args
(
self
,
args
):
def
_count_module_args
(
self
,
args
,
allow_dupes
=
False
):
'''
Count the number of k=v pairs in the supplied module args. This is
basically a specialized version of parse_kv() from utils with a few
...
...
@@ -405,23 +405,26 @@ class Runner(object):
if
args
is
not
None
:
args
=
args
.
encode
(
'utf-8'
)
try
:
lexer
=
shlex
.
shlex
(
args
,
posix
=
True
)
lexer
=
shlex
.
shlex
(
args
)
lexer
.
whitespace
=
'
\t
'
lexer
.
whitespace_split
=
True
lexer
.
quotes
=
'"'
lexer
.
ignore_quotes
=
"'"
vargs
=
list
(
lexer
)
vargs
=
[
x
.
decode
(
'utf-8'
)
for
x
in
lexer
]
except
ValueError
,
ve
:
if
'no closing quotation'
in
str
(
ve
)
.
lower
():
raise
errors
.
AnsibleError
(
"error parsing argument string '
%
s', try quoting the entire line."
%
args
)
else
:
raise
vargs
=
[
x
.
decode
(
'utf-8'
)
for
x
in
vargs
]
for
x
in
vargs
:
if
"="
in
x
:
quoted
=
x
.
startswith
(
'"'
)
and
x
.
endswith
(
'"'
)
or
x
.
startswith
(
"'"
)
and
x
.
endswith
(
"'"
)
if
"="
in
x
and
not
quoted
:
k
,
v
=
x
.
split
(
"="
,
1
)
if
k
in
options
:
raise
errors
.
AnsibleError
(
"a duplicate parameter was found in the argument string (
%
s)"
%
k
)
options
[
k
]
=
v
is_shell_module
=
self
.
module_name
in
(
'command'
,
'shell'
)
is_shell_param
=
k
in
(
'creates'
,
'removes'
,
'chdir'
,
'executable'
)
if
k
in
options
and
not
allow_dupes
:
if
not
(
is_shell_module
and
not
is_shell_param
):
raise
errors
.
AnsibleError
(
"a duplicate parameter was found in the argument string (
%
s)"
%
k
)
if
is_shell_module
and
is_shell_param
or
not
is_shell_module
:
options
[
k
]
=
v
return
len
(
options
)
...
...
@@ -860,7 +863,7 @@ class Runner(object):
# that no variables inadvertantly (or maliciously) add params
# to the list of args. We do this by counting the number of k=v
# pairs before and after templating.
num_args_pre
=
self
.
_count_module_args
(
module_args
)
num_args_pre
=
self
.
_count_module_args
(
module_args
,
allow_dupes
=
True
)
module_args
=
template
.
template
(
self
.
basedir
,
module_args
,
inject
,
fail_on_undefined
=
self
.
error_on_undefined_vars
)
num_args_post
=
self
.
_count_module_args
(
module_args
)
if
num_args_pre
!=
num_args_post
:
...
...
library/commands/command
View file @
46b47a55
...
...
@@ -205,16 +205,21 @@ class CommandModule(AnsibleModule):
# use shlex to split up the args, while being careful to preserve
# single quotes so they're not removed accidentally
lexer
=
shlex
.
shlex
(
args
,
posix
=
True
)
lexer
=
shlex
.
shlex
(
args
)
lexer
.
whitespace
=
'
\t
'
lexer
.
whitespace_split
=
True
lexer
.
quotes
=
'"'
lexer
.
ignore_quotes
=
"'"
items
=
list
(
lexer
)
for
x
in
items
:
if
'='
in
x
:
quoted
=
x
.
startswith
(
'"'
)
and
x
.
endswith
(
'"'
)
or
x
.
startswith
(
"'"
)
and
x
.
endswith
(
"'"
)
if
'='
in
x
and
not
quoted
:
# check to see if this is a special parameter for the command
k
,
v
=
x
.
split
(
'='
,
1
)
# because we're not breaking out quotes in the shlex split
# above, the value of the k=v pair may still be quoted. If
# so, remove them.
if
len
(
v
)
>
1
and
(
v
.
startswith
(
'"'
)
and
v
.
endswith
(
'"'
)
or
v
.
startswith
(
"'"
)
and
v
.
endswith
(
"'"
)):
v
=
v
[
1
:
-
1
]
if
k
in
(
'creates'
,
'removes'
,
'chdir'
,
'executable'
,
'NO_LOG'
):
if
k
==
"chdir"
:
v
=
os
.
path
.
abspath
(
os
.
path
.
expanduser
(
v
))
...
...
@@ -227,7 +232,7 @@ class CommandModule(AnsibleModule):
params
[
k
]
=
v
# Remove any of the above k=v params from the args string
args
=
PARAM_REGEX
.
sub
(
''
,
args
)
params
[
'args'
]
=
args
params
[
'args'
]
=
args
.
strip
()
return
(
params
,
params
[
'args'
])
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment