From ef650aa3e109ec46e36826d232a2896be5388d39 Mon Sep 17 00:00:00 2001 From: Longxiang Lyu Date: Tue, 7 Mar 2023 14:08:02 +0000 Subject: [PATCH] [config_facts] Add port list `member` to `PORTCHANNEL` Signed-off-by: Longxiang Lyu --- ansible/library/config_facts.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ansible/library/config_facts.py b/ansible/library/config_facts.py index e4feb6f801..57b7dc1489 100644 --- a/ansible/library/config_facts.py +++ b/ansible/library/config_facts.py @@ -134,6 +134,16 @@ def get_facts(config, namespace): return results + +def _add_member_list_to_portchannel(config_facts): + """Add `member` field to PORTCHANNEL table.""" + if "PORTCHANNEL" in config_facts and "PORTCHANNEL_MEMBER" in config_facts: + for pc, pc_config in config_facts["PORTCHANNEL"].items(): + if pc in config_facts["PORTCHANNEL_MEMBER"]: + member_ports = list(config_facts["PORTCHANNEL_MEMBER"][pc].keys()) + pc_config["members"] = member_ports + + def main(): module = AnsibleModule( argument_spec=dict( @@ -163,6 +173,10 @@ def main(): elif m_args["source"] == "running": config = get_running_config(module, namespace) results = get_facts(config, namespace) + + # NOTE: This is a workaround to allow getting port channel members from + # PORTCHANNEL table. + _add_member_list_to_portchannel(results) module.exit_json(ansible_facts=results) except Exception as e: tb = traceback.format_exc()