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
40fd778e
Commit
40fd778e
authored
Mar 14, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
'shell' is a magic module that executes the command module with shell=True
parent
73d20b81
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
5 deletions
+30
-5
lib/ansible/runner.py
+6
-0
lib/ansible/utils.py
+1
-1
library/command
+14
-4
test/TestRunner.py
+9
-0
No files found.
lib/ansible/runner.py
View file @
40fd778e
...
@@ -308,6 +308,12 @@ class Runner(object):
...
@@ -308,6 +308,12 @@ class Runner(object):
because those require extra work.
because those require extra work.
'''
'''
# hack to make the 'shell' module keyword really be executed
# by the command module
if
self
.
module_name
==
'shell'
:
self
.
module_name
=
'command'
self
.
module_args
.
append
(
"#USE_SHELL"
)
module
=
self
.
_transfer_module
(
conn
,
tmp
,
self
.
module_name
)
module
=
self
.
_transfer_module
(
conn
,
tmp
,
self
.
module_name
)
result
=
self
.
_execute_module
(
conn
,
tmp
,
module
,
self
.
module_args
)
result
=
self
.
_execute_module
(
conn
,
tmp
,
module
,
self
.
module_args
)
...
...
lib/ansible/utils.py
View file @
40fd778e
...
@@ -120,7 +120,7 @@ def host_report_msg(hostname, module_name, result, oneline):
...
@@ -120,7 +120,7 @@ def host_report_msg(hostname, module_name, result, oneline):
''' summarize the JSON results for a particular host '''
''' summarize the JSON results for a particular host '''
buf
=
''
buf
=
''
failed
=
is_failed
(
result
)
failed
=
is_failed
(
result
)
if
module_name
==
'command'
:
if
module_name
in
[
'command'
,
'shell'
]
:
if
not
failed
:
if
not
failed
:
buf
=
command_success_msg
(
hostname
,
result
,
oneline
)
buf
=
command_success_msg
(
hostname
,
result
,
oneline
)
else
:
else
:
...
...
library/command
View file @
40fd778e
...
@@ -32,18 +32,27 @@ import os
...
@@ -32,18 +32,27 @@ import os
argfile
=
sys
.
argv
[
1
]
argfile
=
sys
.
argv
[
1
]
args
=
open
(
argfile
,
'r'
)
.
read
()
args
=
open
(
argfile
,
'r'
)
.
read
()
args
=
shlex
.
split
(
args
)
shell
=
False
if
args
.
find
(
"#USE_SHELL"
)
!=
-
1
:
args
=
args
.
replace
(
"#USE_SHELL"
,
""
)
shell
=
True
if
not
shell
:
args
=
shlex
.
split
(
args
)
startd
=
datetime
.
datetime
.
now
()
startd
=
datetime
.
datetime
.
now
()
try
:
try
:
cmd
=
subprocess
.
Popen
(
args
,
shell
=
False
,
cmd
=
subprocess
.
Popen
(
args
,
shell
=
shell
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
out
,
err
=
cmd
.
communicate
()
out
,
err
=
cmd
.
communicate
()
except
(
OSError
,
IOError
),
e
:
except
(
OSError
,
IOError
),
e
:
print
json
.
dumps
({
print
json
.
dumps
({
"failed"
:
1
,
"cmd"
:
args
,
"msg"
:
str
(
e
),
"failed"
:
1
,
"msg"
:
str
(
e
),
})
})
sys
.
exit
(
1
)
sys
.
exit
(
1
)
except
:
except
:
...
@@ -62,6 +71,7 @@ if err is None:
...
@@ -62,6 +71,7 @@ if err is None:
err
=
''
err
=
''
result
=
{
result
=
{
"cmd"
:
args
,
"stdout"
:
out
.
strip
(),
"stdout"
:
out
.
strip
(),
"stderr"
:
err
.
strip
(),
"stderr"
:
err
.
strip
(),
"rc"
:
cmd
.
returncode
,
"rc"
:
cmd
.
returncode
,
...
...
test/TestRunner.py
View file @
40fd778e
...
@@ -127,6 +127,7 @@ class TestRunner(unittest.TestCase):
...
@@ -127,6 +127,7 @@ class TestRunner(unittest.TestCase):
assert
result
[
'changed'
]
==
False
assert
result
[
'changed'
]
==
False
def
test_command
(
self
):
def
test_command
(
self
):
# test command module, change trigger, etc
# test command module, change trigger, etc
result
=
self
.
_run
(
'command'
,
[
"/bin/echo"
,
"hi"
])
result
=
self
.
_run
(
'command'
,
[
"/bin/echo"
,
"hi"
])
assert
"failed"
not
in
result
assert
"failed"
not
in
result
...
@@ -134,14 +135,22 @@ class TestRunner(unittest.TestCase):
...
@@ -134,14 +135,22 @@ class TestRunner(unittest.TestCase):
assert
result
[
'rc'
]
==
0
assert
result
[
'rc'
]
==
0
assert
result
[
'stdout'
]
==
'hi'
assert
result
[
'stdout'
]
==
'hi'
assert
result
[
'stderr'
]
==
''
assert
result
[
'stderr'
]
==
''
result
=
self
.
_run
(
'command'
,
[
"/bin/false"
])
result
=
self
.
_run
(
'command'
,
[
"/bin/false"
])
assert
result
[
'rc'
]
==
1
assert
result
[
'rc'
]
==
1
assert
'failed'
not
in
result
assert
'failed'
not
in
result
result
=
self
.
_run
(
'command'
,
[
"/usr/bin/this_does_not_exist"
,
"splat"
])
result
=
self
.
_run
(
'command'
,
[
"/usr/bin/this_does_not_exist"
,
"splat"
])
assert
'msg'
in
result
assert
'msg'
in
result
assert
'failed'
in
result
assert
'failed'
in
result
assert
'rc'
not
in
result
assert
'rc'
not
in
result
result
=
self
.
_run
(
'shell'
,
[
"/bin/echo"
,
"$HOME"
])
assert
'failed'
not
in
result
assert
result
[
'rc'
]
==
0
raise
Exception
(
result
[
'stdout'
])
def
test_setup
(
self
):
def
test_setup
(
self
):
output
=
self
.
_get_stage_file
(
'output.json'
)
output
=
self
.
_get_stage_file
(
'output.json'
)
result
=
self
.
_run
(
'setup'
,
[
"metadata=
%
s"
%
output
,
"a=2"
,
"b=3"
,
"c=4"
])
result
=
self
.
_run
(
'setup'
,
[
"metadata=
%
s"
%
output
,
"a=2"
,
"b=3"
,
"c=4"
])
...
...
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