From f292f21d867e7ab48b9021ee4aa2612f049e170e Mon Sep 17 00:00:00 2001 From: Sumit Jaiswal Date: Mon, 24 Feb 2020 17:44:21 +0530 Subject: [PATCH] Fixes nxos_l2_interfaces module traceback if allowed vlans are not preconfigured (#67457) * fixes 67455 * fix review --- .../nxos/config/l2_interfaces/l2_interfaces.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/ansible/module_utils/network/nxos/config/l2_interfaces/l2_interfaces.py b/lib/ansible/module_utils/network/nxos/config/l2_interfaces/l2_interfaces.py index 9f17c4ba09d..c5bb9978fac 100644 --- a/lib/ansible/module_utils/network/nxos/config/l2_interfaces/l2_interfaces.py +++ b/lib/ansible/module_utils/network/nxos/config/l2_interfaces/l2_interfaces.py @@ -267,7 +267,7 @@ class L2_interfaces(ConfigBase): def set_commands(self, w, have, replace=False): commands = [] - vlan_tobe_added = [] + obj_in_have = flatten_dict(search_obj_in_list(w['name'], have, 'name')) if not obj_in_have: commands = self.add_commands(w) @@ -277,13 +277,19 @@ class L2_interfaces(ConfigBase): if "allowed_vlans" in diff.keys() and diff["allowed_vlans"]: vlan_tobe_added = diff["allowed_vlans"].split(',') vlan_list = vlan_tobe_added[:] - have_vlans = obj_in_have["allowed_vlans"].split(',') + if obj_in_have.get("allowed_vlans"): + have_vlans = obj_in_have["allowed_vlans"].split(',') + else: + have_vlans = [] for w_vlans in vlan_list: if w_vlans in have_vlans: vlan_tobe_added.pop(vlan_tobe_added.index(w_vlans)) if vlan_tobe_added: diff.update({"allowed_vlans": ','.join(vlan_tobe_added)}) - commands = self.add_commands(diff, True) + if have_vlans: + commands = self.add_commands(diff, True) + else: + commands = self.add_commands(diff) return commands commands = self.add_commands(diff) return commands