summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Sowitzki <asowitzk@redhat.com>2021-03-29 21:39:42 +0200
committerGitHub <noreply@github.com>2021-03-29 15:39:42 -0400
commit1527078a8f4fb80cb3f2c48c00b3e683086332eb (patch)
tree9d74101cf71b70cff29727b5824506ea0439a861
parenta84c1a5669716f6c597a656c1fc02d42f60248ee (diff)
downloadansible-1527078a8f4fb80cb3f2c48c00b3e683086332eb.tar.gz
pause - do not continue with '\r' when timeout is set (#74030)
Original function of pause was, to only allow user input (finished with enter) when no timeout was set. This restores the behaviour.
-rw-r--r--changelogs/fragments/73948-pause-no-enter-with-timeout.yml2
-rw-r--r--lib/ansible/plugins/action/pause.py27
-rwxr-xr-xtest/integration/targets/pause/test-pause.py16
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()