Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the range part while parsing hostname and port #14206

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 3 additions & 6 deletions lib/ansible/inventory/ini.py
Expand Up @@ -110,20 +110,17 @@ def _parse_base_groups(self):
continue
hostname = tokens[0]
port = C.DEFAULT_REMOTE_PORT
hostname_norange = re.sub(r'\[.+\]', '', hostname)
# 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.count(":") > 1:
if hostname_norange.count(":") > 1:
# Possible an IPv6 address, or maybe a host line with multiple ranges
# IPv6 with Port XXX:XXX::XXX.port
# FQDN foo.example.com
if hostname.count(".") == 1:
(hostname, port) = hostname.rsplit(".", 1)
elif ("[" in hostname and
"]" in hostname and
":" in hostname and
(hostname.rindex("]") < hostname.rindex(":")) or
("]" not in hostname and ":" in hostname)):
elif ":" in hostname_norange:
(hostname, port) = hostname.rsplit(":", 1)

hostnames = []
Expand Down
4 changes: 4 additions & 0 deletions test/units/inventory_test_data/complex_hosts
Expand Up @@ -94,3 +94,7 @@ blade-[a:c]-[1:16]
blade-[d:z]-[01:16].example.com
blade-[1:10]-[1:16]
host-e-[10:16].example.net:1234
server-[01:09].dc1
server-[01:09].dc1:5678
server-[01:09:2].dc1
server-[01:09:2].dc1:5678