Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
9d193d8f
Commit
9d193d8f
authored
Aug 31, 2015
by
Toshio Kuratomi
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #12173 from ansible/pr/10204
Rebase of 10204 - Add host key for ssh url only.
parents
fca27c29
58c35391
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
16 deletions
+26
-16
lib/ansible/module_utils/known_hosts.py
+26
-16
No files found.
lib/ansible/module_utils/known_hosts.py
View file @
9d193d8f
...
@@ -40,25 +40,38 @@ def add_git_host_key(module, url, accept_hostkey=True, create_dir=True):
...
@@ -40,25 +40,38 @@ def add_git_host_key(module, url, accept_hostkey=True, create_dir=True):
""" idempotently add a git url hostkey """
""" idempotently add a git url hostkey """
fqdn
=
get_fqdn
(
url
)
if
is_ssh_url
(
url
):
if
fqdn
:
fqdn
=
get_fqdn
(
url
)
known_host
=
check_hostkey
(
module
,
fqdn
)
if
not
known_host
:
if
fqdn
:
if
accept_hostkey
:
known_host
=
check_hostkey
(
module
,
fqdn
)
rc
,
out
,
err
=
add_host_key
(
module
,
fqdn
,
create_dir
=
create_dir
)
if
not
known_host
:
if
rc
!=
0
:
if
accept_hostkey
:
module
.
fail_json
(
msg
=
"failed to add
%
s hostkey:
%
s"
%
(
fqdn
,
out
+
err
))
rc
,
out
,
err
=
add_host_key
(
module
,
fqdn
,
create_dir
=
create_dir
)
else
:
if
rc
!=
0
:
module
.
fail_json
(
msg
=
"
%
s has an unknown hostkey. Set accept_hostkey to True or manually add the hostkey prior to running the git module"
%
fqdn
)
module
.
fail_json
(
msg
=
"failed to add
%
s hostkey:
%
s"
%
(
fqdn
,
out
+
err
))
else
:
module
.
fail_json
(
msg
=
"
%
s has an unknown hostkey. Set accept_hostkey to True or manually add the hostkey prior to running the git module"
%
fqdn
)
def
is_ssh_url
(
url
):
""" check if url is ssh """
if
"@"
in
url
and
"://"
not
in
url
:
return
True
for
scheme
in
"ssh://"
,
"git+ssh://"
,
"ssh+git://"
:
if
url
.
startswith
(
scheme
):
return
True
return
False
def
get_fqdn
(
repo_url
):
def
get_fqdn
(
repo_url
):
""" chop the hostname out of a
git
url """
""" chop the hostname out of a url """
result
=
None
result
=
None
if
"@"
in
repo_url
and
"://"
not
in
repo_url
:
if
"@"
in
repo_url
and
"://"
not
in
repo_url
:
# most likely a
git@ or ssh+git@
type URL
# most likely a
n 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
":"
in
repo_url
:
repo_url
=
repo_url
.
split
(
":"
)[
0
]
repo_url
=
repo_url
.
split
(
":"
)[
0
]
...
@@ -69,9 +82,6 @@ def get_fqdn(repo_url):
...
@@ -69,9 +82,6 @@ def get_fqdn(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
)
if
'ssh'
not
in
parts
[
0
]
and
'git'
not
in
parts
[
0
]:
# don't try and scan a hostname that's not ssh
return
None
# parts[1] will be empty on python2.4 on ssh:// or git:// urls, so
# parts[1] will be empty on python2.4 on ssh:// or git:// urls, so
# ensure we actually have a parts[1] before continuing.
# ensure we actually have a parts[1] before continuing.
if
parts
[
1
]
!=
''
:
if
parts
[
1
]
!=
''
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment