Last active
April 3, 2018 15:14
-
-
Save samdoran/f98bf54ede6d1b8b8e482159dc9a78d7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/lib/ansible/modules/utilities/logic/pause.py b/lib/ansible/modules/utilities/logic/pause.py | |
| index 4f0c8db663..cbb1fe5d44 100644 | |
| --- a/lib/ansible/modules/utilities/logic/pause.py | |
| +++ b/lib/ansible/modules/utilities/logic/pause.py | |
| @@ -34,6 +34,7 @@ options: | |
| prompt: | |
| description: | |
| - Optional text to use for the prompt message. | |
| + - When a custom prompt is supplied without C(minutes) or C(seconds), this puts the module in interactive mode. To abort, press Ctrl + C, then Enter. | |
| echo: | |
| description: | |
| - Contols whether or not keyboard input is shown when typing. | |
| diff --git a/lib/ansible/plugins/action/pause.py b/lib/ansible/plugins/action/pause.py | |
| index fefa521825..d5b43db236 100644 | |
| --- a/lib/ansible/plugins/action/pause.py | |
| +++ b/lib/ansible/plugins/action/pause.py | |
| @@ -59,6 +59,7 @@ class ActionModule(ActionBase): | |
| del tmp # tmp no longer has any effect | |
| duration_unit = 'minutes' | |
| + is_interactive = False | |
| prompt = None | |
| seconds = None | |
| echo = True | |
| @@ -165,7 +166,7 @@ class ActionModule(ActionBase): | |
| intr = termios.tcgetattr(fd)[6][termios.VINTR] | |
| except Exception: | |
| # unsupported/not present, use default | |
| - intr = b'\x03' # value for Ctrl+C | |
| + intr = b'\x03' # value for Ctrl+C | |
| old_settings = termios.tcgetattr(fd) | |
| tty.setraw(fd) | |
| @@ -175,9 +176,12 @@ class ActionModule(ActionBase): | |
| # ICRNL -> Makes the return key work when ICANON is enabled, otherwise | |
| # you get stuck at the prompt with no way to get out of it. | |
| # See man termios for details on these flags | |
| + # | |
| + # Only capture input if a custom prompt is displayed and no timeout is set | |
| if not seconds: | |
| new_settings = termios.tcgetattr(fd) | |
| if 'prompt' in self._task.args: | |
| + is_interactive = True | |
| new_settings[0] = new_settings[0] | termios.ICRNL | |
| new_settings[3] = new_settings[3] | termios.ICANON | |
| @@ -191,7 +195,6 @@ class ActionModule(ActionBase): | |
| # are read in below | |
| termios.tcflush(stdin, termios.TCIFLUSH) | |
| - | |
| while True: | |
| try: | |
| if fd is not None: | |
| @@ -211,11 +214,18 @@ class ActionModule(ActionBase): | |
| result['user_input'] += key_pressed | |
| except KeyboardInterrupt: | |
| - if seconds is not None: | |
| - signal.alarm(0) | |
| - display.display("Press 'C' to continue the play or 'A' to abort \r"), | |
| - if self._c_or_a(stdin): | |
| - break | |
| + if is_interactive: | |
| + # Switch back to non-canonical mode so we can catch the | |
| + # C or A keystrokes immediately | |
| + new_settings = termios.tcgetattr(fd) | |
| + new_settings[0] = new_settings[0] & ~termios.ICRNL | |
| + new_settings[3] = new_settings[3] & ~termios.ICANON & ~termios.ECHO | |
| + termios.tcsetattr(fd, termios.TCSANOW, new_settings) | |
| + signal.alarm(0) | |
| + display.display("Press 'C' to continue the play or 'A' to abort \r"), | |
| + if self._c_or_a(stdin): | |
| + break | |
| + | |
| raise AnsibleError('user requested abort!') | |
| except AnsibleTimeoutExceeded: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment