1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02: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:
James Cammarata 2013-10-09 11:03:07 -05:00
parent f7cbf66d48
commit 948d019fef

View file

@ -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):