diff options
-rw-r--r-- | changelogs/fragments/73948-pause-no-enter-with-timeout.yml | 2 | ||||
-rw-r--r-- | lib/ansible/plugins/action/pause.py | 27 | ||||
-rwxr-xr-x | test/integration/targets/pause/test-pause.py | 16 |
3 files changed, 32 insertions, 13 deletions
diff --git a/changelogs/fragments/73948-pause-no-enter-with-timeout.yml b/changelogs/fragments/73948-pause-no-enter-with-timeout.yml new file mode 100644 index 0000000000..44cc5ebcf8 --- /dev/null +++ b/changelogs/fragments/73948-pause-no-enter-with-timeout.yml @@ -0,0 +1,2 @@ +bugfixes: + - pause - do not accept enter to continue when a timeout is set (https://github.com/ansible/ansible/issues/73948) diff --git a/lib/ansible/plugins/action/pause.py b/lib/ansible/plugins/action/pause.py index cb36709168..728552ad7b 100644 --- a/lib/ansible/plugins/action/pause.py +++ b/lib/ansible/plugins/action/pause.py @@ -246,19 +246,20 @@ class ActionModule(ActionBase): clear_line(stdout) raise KeyboardInterrupt - # read key presses and act accordingly - if key_pressed in (b'\r', b'\n'): - clear_line(stdout) - break - elif key_pressed in backspace: - # delete a character if backspace is pressed - result['user_input'] = result['user_input'][:-1] - clear_line(stdout) - if echo: - stdout.write(result['user_input']) - stdout.flush() - else: - result['user_input'] += key_pressed + if not seconds: + # read key presses and act accordingly + if key_pressed in (b'\r', b'\n'): + clear_line(stdout) + break + elif key_pressed in backspace: + # delete a character if backspace is pressed + result['user_input'] = result['user_input'][:-1] + clear_line(stdout) + if echo: + stdout.write(result['user_input']) + stdout.flush() + else: + result['user_input'] += key_pressed except KeyboardInterrupt: signal.alarm(0) diff --git a/test/integration/targets/pause/test-pause.py b/test/integration/targets/pause/test-pause.py index 866a2df6c9..3703470d06 100755 --- a/test/integration/targets/pause/test-pause.py +++ b/test/integration/targets/pause/test-pause.py @@ -274,3 +274,19 @@ pause_test.send('supersecretpancakes') pause_test.send('\r') pause_test.expect(pexpect.EOF) pause_test.close() + + +# Test that enter presses may not continue the play when a timeout is set. + +pause_test = pexpect.spawn( + 'ansible-playbook', + args=["pause-3.yml"] + args, + timeout=10, + env=os.environ +) + +pause_test.logfile = log_buffer +pause_test.expect(r"\(ctrl\+C then 'C' = continue early, ctrl\+C then 'A' = abort\)") +pause_test.send('\r') +pause_test.expect(pexpect.EOF) +pause_test.close() |