mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Make module_utils.known_hosts.get_fqdn work on ipv6
This commit is contained in:
parent
e595c50197
commit
a7ac98262d
2 changed files with 17 additions and 7 deletions
|
@ -74,12 +74,12 @@ def get_fqdn(repo_url):
|
||||||
if "@" in repo_url and "://" not in repo_url:
|
if "@" in repo_url and "://" not in repo_url:
|
||||||
# most likely an user@host:path or user@host/path type URL
|
# most likely an user@host:path or user@host/path type URL
|
||||||
repo_url = repo_url.split("@", 1)[1]
|
repo_url = repo_url.split("@", 1)[1]
|
||||||
if ":" in repo_url:
|
if repo_url.startswith('['):
|
||||||
repo_url = repo_url.split(":")[0]
|
result = repo_url.split(']', 1)[0] + ']'
|
||||||
result = repo_url
|
elif ":" in repo_url:
|
||||||
|
result = repo_url.split(":")[0]
|
||||||
elif "/" in repo_url:
|
elif "/" in repo_url:
|
||||||
repo_url = repo_url.split("/")[0]
|
result = repo_url.split("/")[0]
|
||||||
result = repo_url
|
|
||||||
elif "://" in repo_url:
|
elif "://" in repo_url:
|
||||||
# this should be something we can parse with urlparse
|
# this should be something we can parse with urlparse
|
||||||
parts = urlparse.urlparse(repo_url)
|
parts = urlparse.urlparse(repo_url)
|
||||||
|
@ -87,11 +87,13 @@ def get_fqdn(repo_url):
|
||||||
# ensure we actually have a parts[1] before continuing.
|
# ensure we actually have a parts[1] before continuing.
|
||||||
if parts[1] != '':
|
if parts[1] != '':
|
||||||
result = parts[1]
|
result = parts[1]
|
||||||
if ":" in result:
|
|
||||||
result = result.split(":")[0]
|
|
||||||
if "@" in result:
|
if "@" in result:
|
||||||
result = result.split("@", 1)[1]
|
result = result.split("@", 1)[1]
|
||||||
|
|
||||||
|
if result[0].startswith('['):
|
||||||
|
result = result.split(']', 1)[0] + ']'
|
||||||
|
elif ":" in result:
|
||||||
|
result = result.split(":")[0]
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def check_hostkey(module, fqdn):
|
def check_hostkey(module, fqdn):
|
||||||
|
|
|
@ -33,6 +33,14 @@ class TestAnsibleModuleKnownHosts(unittest.TestCase):
|
||||||
{'is_ssh_url': True, 'get_fqdn': 'five.example.org'},
|
{'is_ssh_url': True, 'get_fqdn': 'five.example.org'},
|
||||||
'ssh://six.example.org:21/example.org':
|
'ssh://six.example.org:21/example.org':
|
||||||
{'is_ssh_url': True, 'get_fqdn': 'six.example.org'},
|
{'is_ssh_url': True, 'get_fqdn': 'six.example.org'},
|
||||||
|
'ssh://[2001:DB8::abcd:abcd]/example.git':
|
||||||
|
{'is_ssh_url': True, 'get_fqdn': '[2001:DB8::abcd:abcd]'},
|
||||||
|
'ssh://[2001:DB8::abcd:abcd]:22/example.git':
|
||||||
|
{'is_ssh_url': True, 'get_fqdn': '[2001:DB8::abcd:abcd]'},
|
||||||
|
'username@[2001:DB8::abcd:abcd]/example.git':
|
||||||
|
{'is_ssh_url': True, 'get_fqdn': '[2001:DB8::abcd:abcd]'},
|
||||||
|
'username@[2001:DB8::abcd:abcd]:22/example.git':
|
||||||
|
{'is_ssh_url': True, 'get_fqdn': '[2001:DB8::abcd:abcd]'},
|
||||||
}
|
}
|
||||||
|
|
||||||
def test_is_ssh_url(self):
|
def test_is_ssh_url(self):
|
||||||
|
|
Loading…
Reference in a new issue