def check_known_host(user=None, hostname=None, key=None, fingerprint=None, config=None, port=None):
 if (not hostname):
  return {'status': 'error', 'error': 'hostname argument required'}
 if (not user):
  config = (config or '/etc/ssh/ssh_known_hosts')
 else:
  config = (config or '.ssh/known_hosts')
 known_host = get_known_host(user, hostname, config=config, port=port)
 if ((not known_host) or ('fingerprint' not in known_host)):
  return 'add'
 if key:
  return ('exists' if (key == known_host['key']) else 'update')
 elif fingerprint:
  return ('exists' if (fingerprint == known_host['fingerprint']) else 'update')
 else:
  return 'exists'

def check_known_host ( user = None , hostname = None , key = None , fingerprint = None , config = None , port = None ) : if ( not hostname ) : return { 'status' : 'error' , 'error' : 'hostname argument required' } if ( not user ) : config = ( config or '/etc/ssh/ssh_known_hosts' ) else : config = ( config or '.ssh/known_hosts' ) known_host = get_known_host ( user , hostname , config = config , port = port ) if ( ( not known_host ) or ( 'fingerprint' not in known_host ) ) : return 'add' if key : return ( 'exists' if ( key == known_host [ 'key' ] ) else 'update' ) elif fingerprint : return ( 'exists' if ( fingerprint == known_host [ 'fingerprint' ] ) else 'update' ) else : return 'exists'
check the record in known_hosts file .