From 948d019fef8781b22960859caaa93485a074e339 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Wed, 9 Oct 2013 11:03:07 -0500 Subject: [PATCH] Detect IPv6 addresses in INI inventory Prevents parts of the IPv6 address from being interpreted as a port (for example, :80). Fixes #3888 --- lib/ansible/inventory/ini.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/ansible/inventory/ini.py b/lib/ansible/inventory/ini.py index 1cb79ac8cdb..d983a80b160 100644 --- a/lib/ansible/inventory/ini.py +++ b/lib/ansible/inventory/ini.py @@ -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):