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
75e5b640
Commit
75e5b640
authored
Jul 21, 2014
by
James Cammarata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing up shell quoting issues
parent
59305751
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
9 deletions
+22
-9
library/commands/command
+21
-8
test/integration/roles/setup_ec2/tasks/main.yml
+1
-1
No files found.
library/commands/command
View file @
75e5b640
...
...
@@ -92,6 +92,24 @@ EXAMPLES = '''
creates: /path/to/database
'''
# This is a pretty complex regex, which functions as follows:
#
# 1. (^|\s)
# ^ look for a space or the beginning of the line
# 2. (creates|removes|chdir|executable|NO_LOG)=
# ^ look for a valid param, followed by an '='
# 3. (?P<quote>[\'"])?
# ^ look for an optional quote character, which can either be
# a single or double quote character, and store it for later
# 4. (.*?)
# ^ match everything in a non-greedy manner until...
# 5. (?(quote)(?<!\\)(?P=quote))((?<!\\)(?=\s)|$)
# ^ a non-escaped space or a non-escaped quote of the same kind
# that was matched in the first 'quote' is found, or the end of
# the line is reached
PARAM_REGEX
=
re
.
compile
(
r'(^|\s)(creates|removes|chdir|executable|NO_LOG)=(?P<quote>[\'"])?(.*?)(?(quote)(?<!\\)(?P=quote))((?<!\\)(?=\s)|$)'
)
def
main
():
# the command module is the one ansible module that does not take key=value args
...
...
@@ -201,7 +219,6 @@ class CommandModule(AnsibleModule):
lexer
.
ignore_quotes
=
"'"
items
=
list
(
lexer
)
command_args
=
''
for
x
in
items
:
if
'='
in
x
:
# check to see if this is a special parameter for the command
...
...
@@ -216,13 +233,9 @@ class CommandModule(AnsibleModule):
if
not
(
os
.
path
.
exists
(
v
)):
self
.
fail_json
(
rc
=
258
,
msg
=
"cannot use executable '
%
s': file does not exist"
%
v
)
params
[
k
]
=
v
else
:
# this isn't a valid parameter, so just append it back to the list of arguments
command_args
=
"
%
s
%
s"
%
(
command_args
,
x
)
else
:
# not a param, so just append it to the list of arguments
command_args
=
"
%
s
%
s"
%
(
command_args
,
x
)
params
[
'args'
]
=
command_args
.
strip
()
# Remove any of the above k=v params from the args string
args
=
PARAM_REGEX
.
sub
(
''
,
args
)
params
[
'args'
]
=
args
return
(
params
,
params
[
'args'
])
main
()
test/integration/roles/setup_ec2/tasks/main.yml
View file @
75e5b640
...
...
@@ -17,7 +17,7 @@
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-
name
:
generate random string
command
:
python -c
\"import string,random; print ''.join(random.choice(string.ascii_lowercase) for _ in xrange(8));\
"
command
:
python -c
"import string,random; print ''.join(random.choice(string.ascii_lowercase) for _ in xrange(8));
"
register
:
random_string
tags
:
-
prepare
...
...
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