From 42f44b24c62cd5dca32eb8170d9835d5b171688f Mon Sep 17 00:00:00 2001 From: Jerry Chong Date: Wed, 11 Jul 2018 23:49:32 +0800 Subject: [PATCH] Fix NameError in pause module (#42038) * Fix NameError in pause module * Add comment and changelog Co-authored-by: Jerry Chong --- changelogs/fragments/pause-try-except-curses.yaml | 2 ++ lib/ansible/plugins/action/pause.py | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/pause-try-except-curses.yaml diff --git a/changelogs/fragments/pause-try-except-curses.yaml b/changelogs/fragments/pause-try-except-curses.yaml new file mode 100644 index 00000000000..1e8316f9a0d --- /dev/null +++ b/changelogs/fragments/pause-try-except-curses.yaml @@ -0,0 +1,2 @@ +bugfixes: + - pause - nest try except when importing curses to gracefully fail if curses is not present (https://github.com/ansible/ansible/issues/42004) diff --git a/lib/ansible/plugins/action/pause.py b/lib/ansible/plugins/action/pause.py index abece3adf1b..f021f793adb 100644 --- a/lib/ansible/plugins/action/pause.py +++ b/lib/ansible/plugins/action/pause.py @@ -39,9 +39,14 @@ except ImportError: try: import curses - curses.setupterm() - HAS_CURSES = True -except (ImportError, curses.error): + + # Nest the try except since curses.error is not available if curses did not import + try: + curses.setupterm() + HAS_CURSES = True + except curses.error: + HAS_CURSES = False +except ImportError: HAS_CURSES = False if HAS_CURSES: