Merge pull request #6156 from iiordanov/devel

Add support for checking host against global known host files.

The effect of this is that before this fix if files are spread across the known_hosts file but not in the ~/known_hosts file the hosts will execute sequentially. This PR augments the functionality so that all of the knowns hosts will execute in parallel.
pull/6266/head
Richard Isaacson 11 years ago
commit 92aacb198c

@ -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):

Loading…
Cancel
Save