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
ac3ec0a4
Commit
ac3ec0a4
authored
Oct 01, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1173 from dhozac/command-quote-less
Use a regexp to filter out arguments instead
parents
b86dc96d
6477bdc6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
14 deletions
+24
-14
library/command
+9
-14
test/TestRunner.py
+15
-0
No files found.
library/command
View file @
ac3ec0a4
...
...
@@ -22,8 +22,8 @@ import subprocess
import
sys
import
datetime
import
traceback
import
re
import
shlex
import
pipes
import
os
DOCUMENTATION
=
'''
...
...
@@ -131,7 +131,6 @@ class CommandModule(AnsibleModule):
def
_load_params
(
self
):
''' read the input and return a dictionary and the arguments string '''
args
=
MODULE_ARGS
items
=
shlex
.
split
(
args
)
params
=
{}
params
[
'chdir'
]
=
None
params
[
'shell'
]
=
False
...
...
@@ -139,14 +138,13 @@ class CommandModule(AnsibleModule):
args
=
args
.
replace
(
"#USE_SHELL"
,
""
)
params
[
'shell'
]
=
True
check_args
=
shlex
.
split
(
args
)
l_args
=
[]
for
x
in
check_args
:
if
x
.
startswith
(
"creates="
)
:
r
=
re
.
compile
(
r'(^|\s)(creates|removes|chdir)=(?P<quote>[\'"])?(.*?)(?(quote)(?<!\\)(?P=quote))((?<!\\)(?=\s)|$)'
)
for
m
in
r
.
finditer
(
args
):
v
=
m
.
group
(
4
)
.
replace
(
"
\\
"
,
""
)
if
m
.
group
(
2
)
==
"creates"
:
# do not run the command if the line contains creates=filename
# and the filename already exists. This allows idempotence
# of command executions.
(
k
,
v
)
=
x
.
split
(
"="
,
1
)
if
os
.
path
.
exists
(
v
):
self
.
exit_json
(
cmd
=
args
,
...
...
@@ -156,11 +154,10 @@ class CommandModule(AnsibleModule):
stderr
=
False
,
rc
=
0
)
elif
x
.
startswith
(
"removes="
)
:
elif
m
.
group
(
2
)
==
"removes"
:
# do not run the command if the line contains removes=filename
# and the filename do not exists. This allows idempotence
# of command executions.
(
k
,
v
)
=
x
.
split
(
"="
,
1
)
if
not
os
.
path
.
exists
(
v
):
self
.
exit_json
(
cmd
=
args
,
...
...
@@ -170,17 +167,15 @@ class CommandModule(AnsibleModule):
stderr
=
False
,
rc
=
0
)
elif
x
.
startswith
(
"chdir="
):
(
k
,
v
)
=
x
.
split
(
"="
,
1
)
elif
m
.
group
(
2
)
==
"chdir"
:
v
=
os
.
path
.
expanduser
(
v
)
if
not
(
os
.
path
.
exists
(
v
)
and
os
.
path
.
isdir
(
v
)):
self
.
fail_json
(
msg
=
"cannot change to directory '
%
s': path does not exist"
%
v
)
elif
v
[
0
]
!=
'/'
:
self
.
fail_json
(
msg
=
"the path for 'chdir' argument must be fully qualified"
)
params
[
'chdir'
]
=
v
else
:
l_args
.
append
(
x
)
params
[
'args'
]
=
" "
.
join
([
pipes
.
quote
(
x
)
for
x
in
l_args
])
args
=
r
.
sub
(
""
,
args
)
params
[
'args'
]
=
args
return
(
params
,
params
[
'args'
])
main
()
test/TestRunner.py
View file @
ac3ec0a4
...
...
@@ -138,6 +138,21 @@ class TestRunner(unittest.TestCase):
assert
'failed'
not
in
result
assert
result
[
'rc'
]
==
0
result
=
self
.
_run
(
'command'
,
[
"creates='/tmp/ansible command test'"
,
"chdir=/tmp"
,
"touch"
,
"'ansible command test'"
])
assert
'changed'
in
result
assert
result
[
'rc'
]
==
0
result
=
self
.
_run
(
'command'
,
[
"creates='/tmp/ansible command test'"
,
"false"
])
assert
'skipped'
in
result
result
=
self
.
_run
(
'shell'
,
[
"removes=/tmp/ansible
\\
command
\\
test"
,
"chdir=/tmp"
,
"rm -f 'ansible command test'; echo $?"
])
assert
'changed'
in
result
assert
result
[
'rc'
]
==
0
assert
result
[
'stdout'
]
==
'0'
result
=
self
.
_run
(
'shell'
,
[
"removes=/tmp/ansible
\\
command
\\
test"
,
"false"
])
assert
'skipped'
in
result
def
test_git
(
self
):
self
.
_run
(
'file'
,[
'path=/tmp/gitdemo'
,
'state=absent'
])
self
.
_run
(
'file'
,[
'path=/tmp/gd'
,
'state=absent'
])
...
...
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