mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-01 08:13:08 +00:00
Detect IPv6 addresses in INI inventory
Prevents parts of the IPv6 address from being interpreted as a port (for example, :80). Fixes #3888
This commit is contained in:
@@ -84,17 +84,21 @@ class InventoryParser(object):
|
||||
continue
|
||||
hostname = tokens[0]
|
||||
port = C.DEFAULT_REMOTE_PORT
|
||||
# Two cases to check:
|
||||
# Three cases to check:
|
||||
# 0. A hostname that contains a range pesudo-code and a port
|
||||
# 1. A hostname that contains just a port
|
||||
if (hostname.find("[") != -1 and
|
||||
if hostname.count(":") > 1:
|
||||
# probably an IPv6 addresss, so check for the format
|
||||
# XXX:XXX::XXX.port, otherwise we'll just assume no
|
||||
# port is set
|
||||
if hostname.find(".") != -1:
|
||||
(hostname, port) = hostname.rsplit(".", 1)
|
||||
elif (hostname.find("[") != -1 and
|
||||
hostname.find("]") != -1 and
|
||||
hostname.find(":") != -1 and
|
||||
(hostname.rindex("]") < hostname.rindex(":")) or
|
||||
(hostname.find("]") == -1 and hostname.find(":") != -1)):
|
||||
tokens2 = hostname.rsplit(":", 1)
|
||||
hostname = tokens2[0]
|
||||
port = tokens2[1]
|
||||
(hostname, port) = hostname.rsplit(":", 1)
|
||||
|
||||
hostnames = []
|
||||
if detect_range(hostname):
|
||||
|
||||
Reference in New Issue
Block a user