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
pull/3583/merge
Michael Scherer 11 years ago committed by James Cammarata
parent 1509e995df
commit c9d28e10ad

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

Loading…
Cancel
Save