From 9707ae6490042fb347053f6ad59d2f9bd0562588 Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Sun, 2 Oct 2016 15:11:11 -0400 Subject: [PATCH] adds exception handling for AddConditionError (#5124) AddConditionErrors are now handled by nxos_command and a well formed error is returned from the module --- lib/ansible/modules/network/nxos/nxos_command.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/network/nxos/nxos_command.py b/lib/ansible/modules/network/nxos/nxos_command.py index 9dc01a913c..af302c2f75 100644 --- a/lib/ansible/modules/network/nxos/nxos_command.py +++ b/lib/ansible/modules/network/nxos/nxos_command.py @@ -155,7 +155,7 @@ from ansible.module_utils.network import NetworkModule, NetworkError from ansible.module_utils.netcli import CommandRunner from ansible.module_utils.netcli import FailedConditionsError from ansible.module_utils.netcli import FailedConditionalError -from ansible.module_utils.netcli import AddCommandError +from ansible.module_utils.netcli import AddCommandError, AddConditionError VALID_KEYS = ['command', 'output', 'prompt', 'response'] @@ -214,8 +214,12 @@ def main(): exc = get_exception() warnings.append('duplicate command detected: %s' % cmd) - for item in conditionals: - runner.add_conditional(item) + try: + for item in conditionals: + runner.add_conditional(item) + except AddConditionError: + exc = get_exception() + module.fail_json(msg=str(exc), condition=exc.condition) runner.retries = module.params['retries'] runner.interval = module.params['interval']