@@ -37,7 +37,9 @@ def run(self, tmp=None, task_vars=None):
3737 # List of switch serial numbes obtained directly from NDFC
3838 ndfc_sw_data = self ._task .args ["switch_data" ]
3939 # Data from data model
40- edge_connections = self ._task .args ["edge_connections" ][0 ]["switch" ]
40+ edge_connections = self ._task .args ["edge_connections" ]
41+ if edge_connections :
42+ edge_connections = edge_connections [0 ]["switch" ]
4143 restructured_edge_connections = {}
4244 # For each switch current_sw_policies will be used to store a list of policies currently associated to the switch
4345 # For each switch that has unmanaged policies, the switch IP address and the list of unmanaged policies will be stored
@@ -48,15 +50,25 @@ def run(self, tmp=None, task_vars=None):
4850 }
4951 ]
5052 # Iterate over each item in the data list
51- for item in edge_connections :
52- ip = item ['ip' ]
53- # If the IP is not already a key in the dictionary, add it with an empty list
53+ # for item in edge_connections:
54+ # ip = item['ip']
55+ # # If the IP is not already a key in the dictionary, add it with an empty list
56+ # if ip not in restructured_edge_connections:
57+ # restructured_edge_connections[ip] = []
58+ # # Iterate over each policy and collect the descriptions
59+ # for policy in item['policies']:
60+ # description = policy['description']
61+ # restructured_edge_connections[ip].append(description)
62+
63+ for switch in ndfc_sw_data :
64+ ip = switch ['ipAddress' ]
5465 if ip not in restructured_edge_connections :
5566 restructured_edge_connections [ip ] = []
56- # Iterate over each policy and collect the descriptions
57- for policy in item ['policies' ]:
58- description = policy ['description' ]
59- restructured_edge_connections [ip ].append (description )
67+ for item in edge_connections :
68+ if ip == item ['ip' ]:
69+ for policy in item ['policies' ]:
70+ description = policy ['description' ]
71+ restructured_edge_connections [ip ].append (description )
6072
6173 # Print the resulting dictionary
6274 # print(restructured_edge_connections)
0 commit comments