From 109763203978307bc06f7baee7e73acc6c7e8e9a Mon Sep 17 00:00:00 2001 From: Nathaniel Case Date: Fri, 10 May 2019 03:44:30 -0400 Subject: [PATCH] eos_l2_interface: Handle `Interface does not exist` (#56140) * Fail on switchport error * Handle `Interface does not exist` when gathering switchport. --- lib/ansible/modules/network/eos/eos_l2_interface.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/network/eos/eos_l2_interface.py b/lib/ansible/modules/network/eos/eos_l2_interface.py index d5655d1594b..563a6adc2ae 100644 --- a/lib/ansible/modules/network/eos/eos_l2_interface.py +++ b/lib/ansible/modules/network/eos/eos_l2_interface.py @@ -200,7 +200,7 @@ def map_obj_to_commands(updates, module): return commands -def map_config_to_obj(module): +def map_config_to_obj(module, warnings): config = get_config(module, flags=['| section interface']) configobj = NetworkConfig(indent=3, contents=config) @@ -214,7 +214,10 @@ def map_config_to_obj(module): command = {'command': 'show interfaces {0} switchport | include Switchport'.format(item), 'output': 'text'} command_result = run_commands(module, command) - if command_result[0] != "": + if command_result[0] == "% Interface does not exist": + warnings.append("Could not gather switchport information for {0}: {1}".format(item, command_result[0])) + continue + elif command_result[0] != "": switchport_cfg = command_result[0].split(':')[1].strip() if switchport_cfg == 'Enabled': @@ -302,7 +305,7 @@ def main(): result['warnings'] = warnings want = map_params_to_obj(module) - have = map_config_to_obj(module) + have = map_config_to_obj(module, warnings) commands = map_obj_to_commands((want, have), module) result['commands'] = commands