From c26cac2a536da8275daef1bed889bf4b25dd3cdc Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Wed, 1 Mar 2017 11:41:31 -0600 Subject: [PATCH] catches exception in nxos_command and returns failed message (#22151) Catches exception in Conditional check and returns appropriated failed message --- lib/ansible/modules/network/nxos/nxos_command.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/ansible/modules/network/nxos/nxos_command.py b/lib/ansible/modules/network/nxos/nxos_command.py index dedd607cae..f37d385718 100644 --- a/lib/ansible/modules/network/nxos/nxos_command.py +++ b/lib/ansible/modules/network/nxos/nxos_command.py @@ -161,7 +161,7 @@ from ansible.module_utils.nxos import run_commands from ansible.module_utils.pycompat24 import get_exception from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.six import string_types -from ansible.module_utils.netcli import Conditional +from ansible.module_utils.netcli import Conditional, FailedConditionalError from ansible.module_utils.network_common import ComplexList from ansible.module_utils.nxos import nxos_argument_spec, check_args @@ -241,11 +241,15 @@ def main(): responses = run_commands(module, commands) for item in list(conditionals): - if item(responses): - if match == 'any': - conditionals = list() - break - conditionals.remove(item) + try: + if item(responses): + if match == 'any': + conditionals = list() + break + conditionals.remove(item) + except FailedConditionalError: + exc = get_exception() + module.fail_json(msg=str(exc)) if not conditionals: break