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
60055348
Commit
60055348
authored
Feb 24, 2014
by
Iordan Iordanov
Committed by
James Cammarata
Mar 10, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for checking host against global known host files.
parent
d3b452ec
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
26 deletions
+37
-26
lib/ansible/runner/connection_plugins/ssh.py
+37
-26
No files found.
lib/ansible/runner/connection_plugins/ssh.py
View file @
60055348
...
...
@@ -118,35 +118,46 @@ class Connection(object):
def
not_in_host_file
(
self
,
host
):
if
'USER'
in
os
.
environ
:
host_file
=
os
.
path
.
expandvars
(
"~${USER}/.ssh/known_hosts"
)
user_
host_file
=
os
.
path
.
expandvars
(
"~${USER}/.ssh/known_hosts"
)
else
:
host_file
=
"~/.ssh/known_hosts"
host_file
=
os
.
path
.
expanduser
(
host_file
)
if
not
os
.
path
.
exists
(
host_file
):
print
"previous known host file not found"
return
True
host_fh
=
open
(
host_file
)
data
=
host_fh
.
read
()
host_fh
.
close
()
for
line
in
data
.
split
(
"
\n
"
):
if
line
is
None
or
line
.
find
(
" "
)
==
-
1
:
user_host_file
=
"~/.ssh/known_hosts"
user_host_file
=
os
.
path
.
expanduser
(
user_host_file
)
host_file_list
=
[]
host_file_list
.
append
(
user_host_file
)
host_file_list
.
append
(
"/etc/ssh/ssh_known_hosts"
)
host_file_list
.
append
(
"/etc/ssh/ssh_known_hosts2"
)
hfiles_not_found
=
0
for
hf
in
host_file_list
:
if
not
os
.
path
.
exists
(
hf
):
hfiles_not_found
+=
1
continue
tokens
=
line
.
split
()
if
tokens
[
0
]
.
find
(
self
.
HASHED_KEY_MAGIC
)
==
0
:
# this is a hashed known host entry
try
:
(
kn_salt
,
kn_host
)
=
tokens
[
0
][
len
(
self
.
HASHED_KEY_MAGIC
):]
.
split
(
"|"
,
2
)
hash
=
hmac
.
new
(
kn_salt
.
decode
(
'base64'
),
digestmod
=
sha1
)
hash
.
update
(
host
)
if
hash
.
digest
()
==
kn_host
.
decode
(
'base64'
):
return
False
except
:
# invalid hashed host key, skip it
host_fh
=
open
(
hf
)
data
=
host_fh
.
read
()
host_fh
.
close
()
for
line
in
data
.
split
(
"
\n
"
):
if
line
is
None
or
line
.
find
(
" "
)
==
-
1
:
continue
else
:
# standard host file entry
if
host
in
tokens
[
0
]:
return
False
tokens
=
line
.
split
()
if
tokens
[
0
]
.
find
(
self
.
HASHED_KEY_MAGIC
)
==
0
:
# this is a hashed known host entry
try
:
(
kn_salt
,
kn_host
)
=
tokens
[
0
][
len
(
self
.
HASHED_KEY_MAGIC
):]
.
split
(
"|"
,
2
)
hash
=
hmac
.
new
(
kn_salt
.
decode
(
'base64'
),
digestmod
=
sha1
)
hash
.
update
(
host
)
if
hash
.
digest
()
==
kn_host
.
decode
(
'base64'
):
return
False
except
:
# invalid hashed host key, skip it
continue
else
:
# standard host file entry
if
host
in
tokens
[
0
]:
return
False
if
(
hfiles_not_found
==
len
(
host_file_list
)):
print
"previous known host file not found"
return
True
def
exec_command
(
self
,
cmd
,
tmp_path
,
sudo_user
=
None
,
sudoable
=
False
,
executable
=
'/bin/sh'
,
in_data
=
None
,
su_user
=
None
,
su
=
False
):
...
...
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