mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
allow for vars_prompt and pause prompt to be skipped in non interactive settings
ansible-pull users rejoice
This commit is contained in:
parent
ce52fdebe8
commit
a555a0652e
2 changed files with 40 additions and 30 deletions
|
@ -238,6 +238,7 @@ class PlaybookExecutor:
|
|||
|
||||
def _do_var_prompt(self, varname, private=True, prompt=None, encrypt=None, confirm=False, salt_size=None, salt=None, default=None):
|
||||
|
||||
if sys.__stdin__.isatty():
|
||||
if prompt and default is not None:
|
||||
msg = "%s [%s]: " % (prompt, default)
|
||||
elif prompt:
|
||||
|
@ -266,6 +267,9 @@ class PlaybookExecutor:
|
|||
self._display.display("***** VALUES ENTERED DO NOT MATCH ****")
|
||||
else:
|
||||
result = do_prompt(msg, private)
|
||||
else:
|
||||
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:
|
||||
|
|
|
@ -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,6 +107,7 @@ 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()
|
||||
if isatty(fd):
|
||||
old_settings = termios.tcgetattr(fd)
|
||||
tty.setraw(fd)
|
||||
|
||||
|
@ -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,6 +148,7 @@ class ActionModule(ActionBase):
|
|||
finally:
|
||||
# cleanup and save some information
|
||||
# restore the old settings for the duped stdin fd
|
||||
if isatty(fd):
|
||||
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
|
||||
|
||||
duration = time.time() - start
|
||||
|
|
Loading…
Reference in a new issue