From 3fb3e7e6dce046bec9d2e8c52756f368d18702c8 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Thu, 12 Jun 2014 16:16:42 -0500 Subject: [PATCH] Properly parse urls for ssh-keyscan use Previously, the get_fqdn() function in known_hosts.py only worked with urls that started with git@, and ignored any urls that started with a normal schema type (ie. http:// or ssh://). This patch corrects that by using urlparse to parse the hostname portion out of urls that have a proper schema. Fixes #7474 --- lib/ansible/module_utils/known_hosts.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/known_hosts.py b/lib/ansible/module_utils/known_hosts.py index 522b34302ad..ecfdf639fee 100644 --- a/lib/ansible/module_utils/known_hosts.py +++ b/lib/ansible/module_utils/known_hosts.py @@ -27,6 +27,7 @@ # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import hmac +import urlparse try: from hashlib import sha1 @@ -56,7 +57,8 @@ def get_fqdn(repo_url): """ chop the hostname out of a giturl """ result = None - if "@" in repo_url and not repo_url.startswith("http"): + if "@" in repo_url and "://" not in repo_url: + # most likely a git@ or ssh+git@ type URL repo_url = repo_url.split("@", 1)[1] if ":" in repo_url: repo_url = repo_url.split(":")[0] @@ -64,6 +66,11 @@ def get_fqdn(repo_url): elif "/" in repo_url: repo_url = repo_url.split("/")[0] result = repo_url + elif "://" in repo_url: + # this should be something we can parse with urlparse + parts = urlparse.urlparse(repo_url) + if parts[1] != '': + result = parts[1] return result