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
a555a065
Commit
a555a065
authored
Aug 06, 2015
by
Brian Coca
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow for vars_prompt and pause prompt to be skipped in non interactive settings
ansible-pull users rejoice
parent
ce52fdeb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
31 deletions
+41
-31
lib/ansible/executor/playbook_executor.py
+29
-25
lib/ansible/plugins/action/pause.py
+12
-6
No files found.
lib/ansible/executor/playbook_executor.py
View file @
a555a065
...
...
@@ -238,34 +238,38 @@ class PlaybookExecutor:
def
_do_var_prompt
(
self
,
varname
,
private
=
True
,
prompt
=
None
,
encrypt
=
None
,
confirm
=
False
,
salt_size
=
None
,
salt
=
None
,
default
=
None
):
if
prompt
and
default
is
not
None
:
msg
=
"
%
s [
%
s]: "
%
(
prompt
,
default
)
elif
prompt
:
msg
=
"
%
s: "
%
prompt
else
:
msg
=
'input for
%
s: '
%
varname
def
do_prompt
(
prompt
,
private
):
if
sys
.
stdout
.
encoding
:
msg
=
prompt
.
encode
(
sys
.
stdout
.
encoding
)
if
sys
.
__stdin__
.
isatty
():
if
prompt
and
default
is
not
None
:
msg
=
"
%
s [
%
s]: "
%
(
prompt
,
default
)
elif
prompt
:
msg
=
"
%
s: "
%
prompt
else
:
msg
=
'input for
%
s: '
%
varname
def
do_prompt
(
prompt
,
private
):
if
sys
.
stdout
.
encoding
:
msg
=
prompt
.
encode
(
sys
.
stdout
.
encoding
)
else
:
# when piping the output, or at other times when stdout
# may not be the standard file descriptor, the stdout
# encoding may not be set, so default to something sane
msg
=
prompt
.
encode
(
locale
.
getpreferredencoding
())
if
private
:
return
getpass
.
getpass
(
msg
)
return
raw_input
(
msg
)
if
confirm
:
while
True
:
result
=
do_prompt
(
msg
,
private
)
second
=
do_prompt
(
"confirm "
+
msg
,
private
)
if
result
==
second
:
break
self
.
_display
.
display
(
"***** VALUES ENTERED DO NOT MATCH ****"
)
else
:
# when piping the output, or at other times when stdout
# may not be the standard file descriptor, the stdout
# encoding may not be set, so default to something sane
msg
=
prompt
.
encode
(
locale
.
getpreferredencoding
())
if
private
:
return
getpass
.
getpass
(
msg
)
return
raw_input
(
msg
)
if
confirm
:
while
True
:
result
=
do_prompt
(
msg
,
private
)
second
=
do_prompt
(
"confirm "
+
msg
,
private
)
if
result
==
second
:
break
self
.
_display
.
display
(
"***** VALUES ENTERED DO NOT MATCH ****"
)
else
:
result
=
do_prompt
(
msg
,
private
)
result
=
None
self
.
_display
.
warning
(
"Not prompting as we are not in interactive mode"
)
# if result is false and default is not None
if
not
result
and
default
is
not
None
:
...
...
lib/ansible/plugins/action/pause.py
View file @
a555a065
...
...
@@ -24,6 +24,7 @@ import termios
import
time
import
tty
from
os
import
isatty
from
ansible.errors
import
*
from
ansible.plugins.action
import
ActionBase
...
...
@@ -106,12 +107,13 @@ class ActionModule(ActionBase):
# save the attributes on the existing (duped) stdin so
# that we can restore them later after we set raw mode
fd
=
self
.
_connection
.
_new_stdin
.
fileno
()
old_settings
=
termios
.
tcgetattr
(
fd
)
tty
.
setraw
(
fd
)
if
isatty
(
fd
):
old_settings
=
termios
.
tcgetattr
(
fd
)
tty
.
setraw
(
fd
)
# flush the buffer to make sure no previous key presses
# are read in below
termios
.
tcflush
(
self
.
_connection
.
_new_stdin
,
termios
.
TCIFLUSH
)
# flush the buffer to make sure no previous key presses
# are read in below
termios
.
tcflush
(
self
.
_connection
.
_new_stdin
,
termios
.
TCIFLUSH
)
while
True
:
try
:
...
...
@@ -120,6 +122,9 @@ class ActionModule(ActionBase):
raise
KeyboardInterrupt
if
not
seconds
:
if
not
isatty
(
fd
):
self
.
_display
.
warning
(
"Not waiting from prompt as stdin is not interactive"
)
break
# read key presses and act accordingly
if
key_pressed
==
'
\r
'
:
break
...
...
@@ -143,7 +148,8 @@ class ActionModule(ActionBase):
finally
:
# cleanup and save some information
# restore the old settings for the duped stdin fd
termios
.
tcsetattr
(
fd
,
termios
.
TCSADRAIN
,
old_settings
)
if
isatty
(
fd
):
termios
.
tcsetattr
(
fd
,
termios
.
TCSADRAIN
,
old_settings
)
duration
=
time
.
time
()
-
start
result
[
'stop'
]
=
str
(
datetime
.
datetime
.
now
())
...
...
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