diff --git a/lib/ansible/modules/network/junos/junos_interface.py b/lib/ansible/modules/network/junos/junos_interface.py index ce3df67199..4e57da1811 100644 --- a/lib/ansible/modules/network/junos/junos_interface.py +++ b/lib/ansible/modules/network/junos/junos_interface.py @@ -365,10 +365,12 @@ def main(): have_port = [item.text for item in reply.xpath('lldp-neighbors-information/lldp-neighbor-information/lldp-remote-port-id')] for neighbor in want_neighbors: - if neighbor['host'] not in have_host: - failed_conditions.append('host ' + neighbor['host']) - if neighbor['port'] not in have_port: - failed_conditions.append('port ' + neighbor['port']) + host = neighbor.get('host') + port = neighbor.get('port') + if host and host not in have_host: + failed_conditions.append('host ' + host) + if port and port not in have_port: + failed_conditions.append('port ' + port) if failed_conditions: msg = 'One or more conditional statements have not be satisfied' module.fail_json(msg=msg, failed_conditions=failed_conditions)