Hi
I wanted to parse the below sample data which is list of list in ansible.
Can you please help .Sample data with sample output is given.
Please let me know if any information required
Input_data
data = [
[
“Interface Port-channel1.2345 "Management", is up, line protocol is up”,
“\tDescription: Management”,
“\tMAC address a2c0.0000.0029, MTU 1500”,
“\tIP address 10.60.90.20, virtual IP 10.60.90.20, subnet mask 255.255.254.0”,
" Traffic Statistics for "Management":“,
“\t9437514 packets input, 1486785944 bytes”,
“\t317418739 packets output, 98541126401 bytes”,
“\t33398 packets dropped”,
“\tManagement-only interface. Blocked 3 through-the-device packets”,
“”,
“Interface Port-channel10.2006 "IF6-BW-SNSL-Back-2006", is up, line protocol is up”,
“\tDescription: IF6-BW-SNSL-Back-2006”,
“\tMAC address a2c0.0000.002c, MTU 9184”,
“\tIP address 10.609.90.20, subnet mask 255.255.255.128”,
" Traffic Statistics for "IF6-BW-SNSL-Back-2006":”,
“\t4298991716 packets input, 3242974970758 bytes”,
“\t3054164248 packets output, 1762159698989 bytes”,
“\t5307966 packets dropped”,
“Interface Port-channel10.2007 "IF6-BW-SNSL-Back-2007", is up, line protocol is up”,
“\tDescription: IF6-BW-SNSL-Back-2007”,
“\tMAC address a2c0.0000.002e, MTU 9184”,
“\tIP address 10.260.90.20, subnet mask 255.255.255.128”,
" Traffic Statistics for "IF6-BW-SNSL-Back-2007":“,
“\t23160649155 packets input, 7732171808569 bytes”,
“\t3228105731 packets output, 1530585448804 bytes”,
“\t1866450 packets dropped”,
“Interface Port-channel20.2224 "IF4-BW-SNSL-OPG-COMMSEE-STG-Front-2224", is up, line protocol is up”,
“\tDescription: IF4-BW-SNSL-OPG-COMMSEE-STG-Front-2224”,
“\tMAC address a2c0.0000.0034, MTU 9184”,
“\tIP address 10.110.90.20, subnet mask 255.255.255.248”,
" Traffic Statistics for "IF4-BW-SNSL-OPG-COMMSEE-STG-Front-2224":”,
“\t11905903872 packets input, 8331684605255 bytes”,
“\t6579071731 packets output, 5053307770265 bytes”,
“\t5642609 packets dropped”,
“Interface "nlp_int_tap", is up, line protocol is up”,
“\tMAC address a2c0.0000.0016, MTU 1500”,
“\tIP address 10.460.90.20, subnet mask 255.255.255.248”,
" Traffic Statistics for "nlp_int_tap":“,
“\t8401703 packets input, 2715398692 bytes”,
“\t8396416 packets output, 1417467601 bytes”,
“\t1199 packets dropped”
],
[
“Interface Port-channel1.2345 "Management", is up, line protocol is up”,
“\tDescription: Management”,
“\tMAC address a2c0.0000.0024, MTU 1500”,
“\tIP address 10.30.40.50, virtual IP 10.88.70.60, subnet mask 255.255.254.0”,
" Traffic Statistics for "Management":”,
“\t10149073 packets input, 1617915750 bytes”,
“\t201234462 packets output, 60048310288 bytes”,
“\t33408 packets dropped”,
“\tManagement-only interface. Blocked 1 through-the-device packets”,
“”,
“Interface Port-channel10.2273 "IF3-BW-SNSL-COMMSEC-NONPROD-2273", is up, line protocol is up”,
“\tDescription: Back VLAN for COMMSEC NON-PROD - CONTROLLED”,
“\tMAC address a2c0.0000.0064, MTU 9184”,
“\tIP address 10.30.40.51.158, subnet mask 255.255.255.224”,
" Traffic Statistics for "IF3-BW-SNSL-COMMSEC-NONPROD-2273":“,
“\t4649716537 packets input, 1542339911758 bytes”,
“\t3642754601 packets output, 1099579611260 bytes”,
“\t116423 packets dropped”,
“Interface Port-channel10.2274 "IF5-BW-SNSL-COMMSEC-NONPROD-2274", is up, line protocol is up”,
“\tDescription: Back VLAN for COMMSEC NON-PROD - RESTRICTED”,
“\tMAC address a2c0.0000.0066, MTU 9184”,
“\tIP address 10.30.40.90, subnet mask 255.255.255.224”,
" Traffic Statistics for "IF5-BW-SNSL-COMMSEC-NONPROD-2274":”,
“\t2482332748 packets input, 1470527062853 bytes”,
“\t1414194649 packets output, 216009858627 bytes”,
“\t442777 packets dropped”,
“Interface Port-channel10.2275 "IF6-BW-SNSL-COMMSEC-NONPROD-2275", is up, line protocol is up”,
“\tDescription: Back VLAN for COMMSEC NON-PROD - SECURED”,
“\tMAC address a2c0.0000.0068, MTU 9184”,
“\tIP address 10.30.40.80, subnet mask 255.255.255.224”,
" Traffic Statistics for "IF6-BW-SNSL-COMMSEC-NONPROD-2275":“,
“\t0 packets input, 0 bytes”,
“\t3505 packets output, 117436 bytes”,
“\t0 packets dropped”,
“Interface Port-channel10.2276 "IF7-BW-SNSL-COMMSEC-NONPROD-2276", is up, line protocol is up”,
“\tDescription: Back VLAN for COMMSEC NON-PROD - MANAGEMENT”,
“\tMAC address a2c0.0000.006a, MTU 9184”,
“\tIP address 10.30.40.70, subnet mask 255.255.255.192”,
" Traffic Statistics for "IF7-BW-SNSL-COMMSEC-NONPROD-2276":”,
“\t44895243 packets input, 22490344483 bytes”,
“\t28357798 packets output, 7174133070 bytes”,
“\t49915 packets dropped”,
“Interface Port-channel20.2223 "IF4-BW-SNSL-COMMSEC-NONPROD-2223", is up, line protocol is up”,
“\tDescription: Front VLAN for COMMSEC NON-PROD”,
“\tMAC address a2c0.0000.0062, MTU 9184”,
“\tIP address 10.30.40.90, subnet mask 255.255.255.248”,
" Traffic Statistics for "IF4-BW-SNSL-COMMSEC-NONPROD-2223":“,
“\t2247658749 packets input, 262559718829 bytes”,
“\t2477269288 packets output, 1199976079000 bytes”,
“\t793770 packets dropped”,
“Interface "nlp_int_tap", is up, line protocol is up”,
“\tMAC address a2c0.0000.0018, MTU 1500”,
“\tIP address 10.20.40.50, subnet mask 255.255.255.248”,
" Traffic Statistics for "nlp_int_tap":”,
“\t9119310 packets input, 3057269509 bytes”,
“\t9114023 packets output, 1548838262 bytes”,
“\t1196 packets dropped”
]]
Output should be
Its ok to get output in two ways whichever way is easier
Output should be either list of list or list of dictionary
[[“Port-channel1.2345”, “Management”, “10.60.90.20”, “255.255.254.0”], [“Port-channel10.2006”, “IF6-BW-SNSL-Back-2006”, “10.609.90.20”,“255.255.255.128”]]
Note: Get the description only if it is available in data like “\tDescription: Management”, if not any description then keep empty string
like [[“Port-channel1.2345”, “”, “10.60.90.20”, “255.255.254.0”]]
Dictionary format
[{“interface”: “Port-channel1.2345”,“description”:“Management” , “ip_address”:“10.60.90.20”, “subnet_mask”: “255.255.254.0”}]