From c9d28e10ad792a6942a74c7fc25bb036f8e785b9 Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Sun, 18 Aug 2013 23:02:28 +0200 Subject: [PATCH] add support for using a ipv6 in -i testing with a ipv6 : ansible -u misc -i '[2002::c23e]:22,' '*' -m ping fail due to parsing of ':' as a separator of port/ip with ipv4. This commit add support for properly parsing 2002::c23 and the bracket notation [2002::ce]:2222 --- lib/ansible/inventory/__init__.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/ansible/inventory/__init__.py b/lib/ansible/inventory/__init__.py index 334beb6dc80..228d3b72102 100644 --- a/lib/ansible/inventory/__init__.py +++ b/lib/ansible/inventory/__init__.py @@ -74,12 +74,21 @@ class Inventory(object): self.parser = None all = Group('all') self.groups = [ all ] + ipv6_re = re.compile('\[([a-f:A-F0-9]*)\](?::(\d+))?') for x in host_list: - if ":" in x: - tokens = x.split(":", 1) - all.add_host(Host(tokens[0], tokens[1])) + m = ipv6_re.match(x) + if m: + all.add_host(Host(m.groups()[0], m.groups()[1])) else: - all.add_host(Host(x)) + if ":" in x: + tokens = x.rsplit(":", 1) + # if there is ':' in the address, then this is a ipv6 + if ':' in tokens[0]: + all.add_host(Host(x)) + else: + all.add_host(Host(tokens[0], tokens[1])) + else: + all.add_host(Host(x)) elif os.path.exists(host_list): if os.path.isdir(host_list): # Ensure basedir is inside the directory