Add support for checking host against global known host files.

This commit is contained in:
Iordan Iordanov 2014-02-24 16:05:03 -05:00 committed by James Cammarata
parent d3b452ecb1
commit 60055348ba

View file

@ -118,14 +118,22 @@ 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)
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
host_fh = open(hf)
data = host_fh.read()
host_fh.close()
for line in data.split("\n"):
@ -147,6 +155,9 @@ class Connection(object):
# 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):