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
5bc81f9a
Commit
5bc81f9a
authored
Nov 10, 2014
by
James Cammarata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ability to detect prompts in stdout from run_command
parent
39595232
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
7 deletions
+23
-7
lib/ansible/module_utils/basic.py
+23
-7
No files found.
lib/ansible/module_utils/basic.py
View file @
5bc81f9a
...
...
@@ -1370,7 +1370,7 @@ class AnsibleModule(object):
# rename might not preserve context
self
.
set_context_if_different
(
dest
,
context
,
False
)
def
run_command
(
self
,
args
,
check_rc
=
False
,
close_fds
=
True
,
executable
=
None
,
data
=
None
,
binary_data
=
False
,
path_prefix
=
None
,
cwd
=
None
,
use_unsafe_shell
=
False
):
def
run_command
(
self
,
args
,
check_rc
=
False
,
close_fds
=
True
,
executable
=
None
,
data
=
None
,
binary_data
=
False
,
path_prefix
=
None
,
cwd
=
None
,
use_unsafe_shell
=
False
,
prompt_regex
=
None
):
'''
Execute a command, returns rc, stdout, and stderr.
args is the command to run
...
...
@@ -1378,12 +1378,17 @@ class AnsibleModule(object):
If args is a string and use_unsafe_shell=False it will split args to a list and run with shell=False
If args is a string and use_unsafe_shell=True it run with shell=True.
Other arguments:
- check_rc (boolean) Whether to call fail_json in case of
non zero RC. Default is False.
- close_fds (boolean) See documentation for subprocess.Popen().
Default is True.
- executable (string) See documentation for subprocess.Popen().
Default is None.
- check_rc (boolean) Whether to call fail_json in case of
non zero RC. Default is False.
- close_fds (boolean) See documentation for subprocess.Popen().
Default is True.
- executable (string) See documentation for subprocess.Popen().
Default is None.
- prompt_regex (string) A regex string (not a compiled regex) which
can be used to detect prompts in the stdout
which would otherwise cause the execution
to hang (especially if no input data is
specified)
'''
shell
=
False
...
...
@@ -1399,6 +1404,13 @@ class AnsibleModule(object):
msg
=
"Argument 'args' to run_command must be list or string"
self
.
fail_json
(
rc
=
257
,
cmd
=
args
,
msg
=
msg
)
prompt_re
=
None
if
prompt_regex
:
try
:
prompt_re
=
re
.
compile
(
prompt_regex
,
re
.
MULTILINE
)
except
re
.
error
:
self
.
fail_json
(
msg
=
"invalid prompt regular expression given to run_command"
)
# expand things like $HOME and ~
if
not
shell
:
args
=
[
os
.
path
.
expandvars
(
os
.
path
.
expanduser
(
x
))
for
x
in
args
]
...
...
@@ -1492,6 +1504,10 @@ class AnsibleModule(object):
stderr
+=
dat
if
dat
==
''
:
rpipes
.
remove
(
cmd
.
stderr
)
# if we're checking for prompts, do it now
if
prompt_re
:
if
prompt_re
.
search
(
stdout
)
and
not
data
:
return
(
257
,
stdout
,
"A prompt was encountered while running a command, but no input data was specified"
)
# only break out if no pipes are left to read or
# the pipes are completely read and
# the process is terminated
...
...
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