diff --git a/changelogs/fragments/54971-PN_modules_handling_empty_output_string.yaml b/changelogs/fragments/54971-PN_modules_handling_empty_output_string.yaml new file mode 100644 index 0000000000..77bed6bf10 --- /dev/null +++ b/changelogs/fragments/54971-PN_modules_handling_empty_output_string.yaml @@ -0,0 +1,2 @@ +minor_changes: +- pluribus networks modules to handle empty output string. diff --git a/lib/ansible/modules/network/netvisor/pn_access_list.py b/lib/ansible/modules/network/netvisor/pn_access_list.py index 157247bfb7..a4c78414a8 100644 --- a/lib/ansible/modules/network/netvisor/pn_access_list.py +++ b/lib/ansible/modules/network/netvisor/pn_access_list.py @@ -100,7 +100,10 @@ def check_cli(module, cli): list_name = module.params['pn_name'] cli += ' access-list-show format name no-show-headers' - out = run_commands(module, cli) + out = run_commands(module, cli)[1] + + if out: + out = out.split() return True if list_name in out else False diff --git a/lib/ansible/modules/network/netvisor/pn_cpu_class.py b/lib/ansible/modules/network/netvisor/pn_cpu_class.py index 3d1376e3b0..bc207794df 100644 --- a/lib/ansible/modules/network/netvisor/pn_cpu_class.py +++ b/lib/ansible/modules/network/netvisor/pn_cpu_class.py @@ -124,9 +124,10 @@ def check_cli(module, cli): ) cli = clicopy - cli += ' cpu-class-show name %s format name no-show-headers' % name + cli += ' cpu-class-show format name no-show-headers' out = run_commands(module, cli)[1] - out = out.split() + if out: + out = out.split() return True if name in out else False diff --git a/lib/ansible/modules/network/netvisor/pn_dhcp_filter.py b/lib/ansible/modules/network/netvisor/pn_dhcp_filter.py index b13e779422..f154a67a97 100644 --- a/lib/ansible/modules/network/netvisor/pn_dhcp_filter.py +++ b/lib/ansible/modules/network/netvisor/pn_dhcp_filter.py @@ -103,7 +103,8 @@ def check_cli(module, cli): cli += ' dhcp-filter-show format name no-show-headers' out = run_commands(module, cli)[1] - out = out.split() + if out: + out = out.split() return True if user_name in out else False diff --git a/lib/ansible/modules/network/netvisor/pn_dscp_map.py b/lib/ansible/modules/network/netvisor/pn_dscp_map.py index c38ddaa32b..63de80a3d0 100644 --- a/lib/ansible/modules/network/netvisor/pn_dscp_map.py +++ b/lib/ansible/modules/network/netvisor/pn_dscp_map.py @@ -92,12 +92,13 @@ def check_cli(module, cli): """ name = module.params['pn_name'] - cli += ' dscp-map-show name %s format name no-show-headers' % name + cli += ' dscp-map-show format name no-show-headers' out = run_commands(module, cli)[1] - out = out.split() + if out: + out = out.split() - return True if name in out[-1] else False + return True if name in out else False def main(): diff --git a/lib/ansible/modules/network/netvisor/pn_dscp_map_pri_map.py b/lib/ansible/modules/network/netvisor/pn_dscp_map_pri_map.py index d2b9f20a0e..09eec99f5e 100644 --- a/lib/ansible/modules/network/netvisor/pn_dscp_map_pri_map.py +++ b/lib/ansible/modules/network/netvisor/pn_dscp_map_pri_map.py @@ -100,12 +100,13 @@ def check_cli(module, cli): """ name = module.params['pn_name'] - cli += ' dscp-map-show name %s format name no-show-headers' % name + cli += ' dscp-map-show format name no-show-headers' out = run_commands(module, cli)[1] - out = out.split() + if out: + out = out.split() - return True if name in out[-1] else False + return True if name in out else False def main(): diff --git a/lib/ansible/modules/network/netvisor/pn_prefix_list_network.py b/lib/ansible/modules/network/netvisor/pn_prefix_list_network.py index 17ef7fa838..bc2f10786d 100644 --- a/lib/ansible/modules/network/netvisor/pn_prefix_list_network.py +++ b/lib/ansible/modules/network/netvisor/pn_prefix_list_network.py @@ -116,7 +116,7 @@ def check_cli(module, cli): rc, out, err = run_commands(module, cli) if out: - out = out.split()[1] + out = out.split()[-1] return True if network in out.split('/')[0] else False return False diff --git a/lib/ansible/modules/network/netvisor/pn_role.py b/lib/ansible/modules/network/netvisor/pn_role.py index 44fbb20a87..ba2306de7f 100644 --- a/lib/ansible/modules/network/netvisor/pn_role.py +++ b/lib/ansible/modules/network/netvisor/pn_role.py @@ -133,7 +133,8 @@ def check_cli(module, cli): cli += ' role-show format name no-show-headers' out = run_commands(module, cli)[1] - out = out.split() + if out: + out = out.split() return True if role_name in out else False diff --git a/lib/ansible/modules/network/netvisor/pn_snmp_community.py b/lib/ansible/modules/network/netvisor/pn_snmp_community.py index f74f539718..1679ca4fcb 100644 --- a/lib/ansible/modules/network/netvisor/pn_snmp_community.py +++ b/lib/ansible/modules/network/netvisor/pn_snmp_community.py @@ -102,7 +102,8 @@ def check_cli(module, cli): cli += ' snmp-community-show format community-string no-show-headers' out = run_commands(module, cli)[1] - out = out.split() + if out: + out = out.split() return True if comm_str in out else False diff --git a/lib/ansible/modules/network/netvisor/pn_snmp_trap_sink.py b/lib/ansible/modules/network/netvisor/pn_snmp_trap_sink.py index 84a3dec70c..f8e90a1a6e 100644 --- a/lib/ansible/modules/network/netvisor/pn_snmp_trap_sink.py +++ b/lib/ansible/modules/network/netvisor/pn_snmp_trap_sink.py @@ -110,14 +110,16 @@ def check_cli(module, cli): cli += ' snmp-community-show format community-string no-show-headers' rc, out, err = run_commands(module, cli) - out = out.split() + if out: + out = out.split() if community in out: cli = show cli += ' snmp-trap-sink-show community %s format type,dest-host no-show-headers' % community rc, out, err = run_commands(module, cli) - out = out.split() + if out: + out = out.split() return True if dest_host in out else False else: diff --git a/lib/ansible/modules/network/netvisor/pn_snmp_vacm.py b/lib/ansible/modules/network/netvisor/pn_snmp_vacm.py index 72231d9cfb..77b67ef071 100644 --- a/lib/ansible/modules/network/netvisor/pn_snmp_vacm.py +++ b/lib/ansible/modules/network/netvisor/pn_snmp_vacm.py @@ -113,9 +113,10 @@ def check_cli(module, cli): user_name = module.params['pn_user_name'] show = cli - cli += ' snmp-user-show user-name %s format user-name no-show-headers' % user_name + cli += ' snmp-user-show format user-name no-show-headers' rc, out, err = run_commands(module, cli) - if out: + + if out and user_name in out.split(): pass else: return None @@ -124,7 +125,8 @@ def check_cli(module, cli): cli += ' snmp-vacm-show format user-name no-show-headers' out = run_commands(module, cli)[1] - out = out.split() + if out: + out = out.split() return True if user_name in out else False diff --git a/lib/ansible/modules/network/netvisor/pn_vrouter_interface_ip.py b/lib/ansible/modules/network/netvisor/pn_vrouter_interface_ip.py index 7c6aa08d30..0cfe81479c 100644 --- a/lib/ansible/modules/network/netvisor/pn_vrouter_interface_ip.py +++ b/lib/ansible/modules/network/netvisor/pn_vrouter_interface_ip.py @@ -131,11 +131,12 @@ def check_cli(module, cli): nic_str = module.params['pn_nic'] # Check for vRouter - check_vrouter = cli + ' vrouter-show name %s format name no-show-headers ' % vrouter_name + check_vrouter = cli + ' vrouter-show format name no-show-headers' out = run_commands(module, check_vrouter)[1] - out = out.split() + if out: + out = out.split() - VROUTER_EXISTS = True if vrouter_name in out[-1] else False + VROUTER_EXISTS = True if vrouter_name in out else False if interface_ip: # Check for interface and VRRP and fetch nic for VRRP @@ -151,9 +152,11 @@ def check_cli(module, cli): if nic_str: # Check for nic show = cli + ' vrouter-interface-show vrouter-name %s ' % vrouter_name - show += ' format nic no-show-headers' + show += 'format nic no-show-headers' out = run_commands(module, show)[1] - out = out.split() + + if out: + out = out.split() NIC_EXISTS = True if nic_str in out else False @@ -221,7 +224,7 @@ def main(): if INTERFACE_EXISTS is True: module.exit_json( skipped=True, - msg='vRouter with interface %s exist' % ip + msg='vRouter with interface ip %s exist' % ip ) cli += ' nic %s ip %s ' % (nic, ip) @@ -236,7 +239,7 @@ def main(): if INTERFACE_EXISTS is False: module.exit_json( skipped=True, - msg='vRouter with interface %s does not exist' % ip + msg='vRouter with interface ip %s does not exist' % ip ) if nic: cli += ' nic %s ' % nic diff --git a/lib/ansible/modules/network/netvisor/pn_vrouter_ospf6.py b/lib/ansible/modules/network/netvisor/pn_vrouter_ospf6.py index 094123ba30..7fbebb7cf0 100644 --- a/lib/ansible/modules/network/netvisor/pn_vrouter_ospf6.py +++ b/lib/ansible/modules/network/netvisor/pn_vrouter_ospf6.py @@ -111,7 +111,8 @@ def check_cli(module, cli): # Check for vRouter check_vrouter = cli + ' vrouter-show format name no-show-headers ' out = run_commands(module, check_vrouter)[1] - out = out.split() + if out: + out = out.split() VROUTER_EXISTS = True if vrouter_name in out else False @@ -120,6 +121,9 @@ def check_cli(module, cli): show = cli + ' vrouter-ospf6-show vrouter-name %s format nic no-show-headers' % vrouter_name out = run_commands(module, show)[1] + if out: + out.split() + NIC_EXISTS = True if nic_str in out else False return VROUTER_EXISTS, NIC_EXISTS diff --git a/lib/ansible/modules/network/netvisor/pn_vrouter_pim_config.py b/lib/ansible/modules/network/netvisor/pn_vrouter_pim_config.py index a348daadd5..0c93761e3f 100644 --- a/lib/ansible/modules/network/netvisor/pn_vrouter_pim_config.py +++ b/lib/ansible/modules/network/netvisor/pn_vrouter_pim_config.py @@ -97,10 +97,11 @@ def check_cli(module, cli): name = module.params['pn_vrouter_name'] show = cli - cli += ' vrouter-show name %s format name no-show-headers ' % name + cli += ' vrouter-show format name no-show-headers ' out = run_commands(module, cli)[1] - out = out.split() - if out[-1] == name: + if out: + out = out.split() + if name in out: pass else: return False @@ -108,7 +109,8 @@ def check_cli(module, cli): cli = show cli += ' vrouter-show name %s format proto-multi no-show-headers' % name out = run_commands(module, cli)[1] - out = out.split() + if out: + out = out.split() return True if 'none' not in out else False