update nmap inventory plugin to not depend on rdns (#56457)

This commit is contained in:
Dennis Israelsson 2020-02-05 23:29:59 +01:00 committed by GitHub
parent 0e46af17a5
commit 68b981ae21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -65,7 +65,7 @@ from ansible.module_utils.common.process import get_bin_path
class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
NAME = 'nmap'
find_host = re.compile(r'^Nmap scan report for ([\w,.,-]+) \(([\w,.,:,\[,\]]+)\)')
find_host = re.compile(r'^Nmap scan report for ([\w,.,-]+)(?: \(([\w,.,:,\[,\]]+)\))?')
find_port = re.compile(r'^(\d+)/(\w+)\s+(\w+)\s+(\w+)')
def __init__(self):
@ -140,7 +140,11 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
else:
host = hits.group(1)
ip = hits.group(2)
# if no reverse dns exists, just use ip instead as hostname
if hits.group(2) is not None:
ip = hits.group(2)
else:
ip = hits.group(1)
if host is not None:
# update inventory