From f5e72c65900ddc922b28ab403d0b2d14fb5febb3 Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Sun, 2 Oct 2016 14:57:58 -0400 Subject: [PATCH] adds check for AddConditionError when adding conditional statements (#5123) The Conditional instance will now raise the AddConditionError and this change instructs eos_command to catch the error and return a nicely formed error message --- lib/ansible/modules/network/eos/eos_command.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/network/eos/eos_command.py b/lib/ansible/modules/network/eos/eos_command.py index a506075b26..e1a0f806df 100644 --- a/lib/ansible/modules/network/eos/eos_command.py +++ b/lib/ansible/modules/network/eos/eos_command.py @@ -149,7 +149,7 @@ import ansible.module_utils.eos from ansible.module_utils.basic import get_exception from ansible.module_utils.network import NetworkModule, NetworkError from ansible.module_utils.netcli import CommandRunner -from ansible.module_utils.netcli import AddCommandError +from ansible.module_utils.netcli import AddCommandError, AddConditionError from ansible.module_utils.netcli import FailedConditionsError from ansible.module_utils.netcli import FailedConditionalError from ansible.module_utils.six import string_types @@ -212,8 +212,13 @@ 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']