diff options
author | Sam Doran <sdoran@redhat.com> | 2021-02-05 15:50:33 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-05 14:50:33 -0600 |
commit | e3c08d001d8ae787b95ceeacd07938f751f6b516 (patch) | |
tree | 0e66fe02217421edd22911cef33bb5be0ecd6334 | |
parent | 3361517fa964222128e232eec20107b3b6547b70 (diff) | |
download | ansible-e3c08d001d8ae787b95ceeacd07938f751f6b516.tar.gz |
[stable-2.9] pause - adjust warning when run in background (#73182) (#73230)
When the pause module is run in the background and seconds parameter is provided,
do not warn.
* Add tests
* Fix existing tests
The test wasn't failing when it should have.
(cherry picked from commit 0e6c334115)
Co-authored-by: Sam Doran <sdoran@redhat.com>
-rw-r--r-- | changelogs/fragments/pause-do-not-warn-background-with-seconds.yml | 2 | ||||
-rw-r--r-- | lib/ansible/plugins/action/pause.py | 3 | ||||
-rwxr-xr-x | test/integration/targets/pause/runme.sh | 25 |
3 files changed, 23 insertions, 7 deletions
diff --git a/changelogs/fragments/pause-do-not-warn-background-with-seconds.yml b/changelogs/fragments/pause-do-not-warn-background-with-seconds.yml new file mode 100644 index 0000000000..5856e7c40f --- /dev/null +++ b/changelogs/fragments/pause-do-not-warn-background-with-seconds.yml @@ -0,0 +1,2 @@ +bugfixes: + - pause - do not warn when running in the background if a timeout is provided (https://github.com/ansible/ansible/issues/73042) diff --git a/lib/ansible/plugins/action/pause.py b/lib/ansible/plugins/action/pause.py index b7731ff21e..961b1e0c55 100644 --- a/lib/ansible/plugins/action/pause.py +++ b/lib/ansible/plugins/action/pause.py @@ -231,7 +231,8 @@ class ActionModule(ActionBase): while True: if not interactive: - display.warning("Not waiting for response to prompt as stdin is not interactive") + if seconds is None: + display.warning("Not waiting for response to prompt as stdin is not interactive") if seconds is not None: # Give the signal handler enough time to timeout time.sleep(seconds + 1) diff --git a/test/integration/targets/pause/runme.sh b/test/integration/targets/pause/runme.sh index 932f49ec2d..eb2c6f7c7e 100755 --- a/test/integration/targets/pause/runme.sh +++ b/test/integration/targets/pause/runme.sh @@ -4,8 +4,8 @@ set -eux ANSIBLE_ROLES_PATH=../ ansible-playbook setup.yml -# Test pause module when no tty and non-interactive. This is to prevent playbooks -# from hanging in cron and Tower jobs. +# Test pause module when no tty and non-interactive with no seconds parameter. +# This is to prevent playbooks from hanging in cron and Tower jobs. /usr/bin/env bash << EOF ansible-playbook test-pause-no-tty.yml 2>&1 | \ grep '\[WARNING\]: Not waiting for response to prompt as stdin is not interactive' && { @@ -17,11 +17,24 @@ ansible-playbook test-pause-no-tty.yml 2>&1 | \ } EOF +# Do not issue a warning when run in the background if a timeout is given +# https://github.com/ansible/ansible/issues/73042 +if sleep 0 | ansible localhost -m pause -a 'seconds=1' 2>&1 | grep '\[WARNING\]: Not waiting for response'; then + echo "Incorrectly issued warning when run in the background" + exit 1 +else + echo "Succesfully ran in the background with no warning" +fi + # Test redirecting stdout -# Issue #41717 -ansible-playbook pause-3.yml > /dev/null \ - && echo "Successfully redirected stdout" \ - || echo "Failure when attempting to redirect stdout" +# https://github.com/ansible/ansible/issues/41717 +if ansible-playbook pause-3.yml > /dev/null ; then + echo "Successfully redirected stdout" +else + echo "Failure when attempting to redirect stdout" + exit 1 +fi + # Test pause with seconds and minutes specified ansible-playbook test-pause.yml "$@" |