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