1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

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
This commit is contained in:
Michael Scherer 2013-08-18 23:02:28 +02:00 committed by James Cammarata
parent 1509e995df
commit c9d28e10ad

View file

@ -74,12 +74,21 @@ class Inventory(object):
self.parser = None self.parser = None
all = Group('all') all = Group('all')
self.groups = [ all ] self.groups = [ all ]
ipv6_re = re.compile('\[([a-f:A-F0-9]*)\](?::(\d+))?')
for x in host_list: for x in host_list:
if ":" in x: m = ipv6_re.match(x)
tokens = x.split(":", 1) if m:
all.add_host(Host(tokens[0], tokens[1])) all.add_host(Host(m.groups()[0], m.groups()[1]))
else: 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): elif os.path.exists(host_list):
if os.path.isdir(host_list): if os.path.isdir(host_list):
# Ensure basedir is inside the directory # Ensure basedir is inside the directory