def rm_known_host(user=None, hostname=None, config=None, port=None):
 if (not hostname):
  return {'status': 'error', 'error': 'hostname argument required'}
 full = _get_known_hosts_file(config=config, user=user)
 if isinstance(full, dict):
  return full
 if (not os.path.isfile(full)):
  return {'status': 'error', 'error': 'Known hosts file {0} does not exist'.format(full)}
 ssh_hostname = _hostname_and_port_to_ssh_hostname(hostname, port)
 cmd = ['ssh-keygen', '-R', ssh_hostname, '-f', full]
 cmd_result = __salt__['cmd.run'](cmd, python_shell=False)
 if ((os.geteuid() == 0) and user):
  uinfo = __salt__['user.info'](user)
  os.chown(full, uinfo['uid'], uinfo['gid'])
 return {'status': 'removed', 'comment': cmd_result}

def rm_known_host ( user = None , hostname = None , config = None , port = None ) : if ( not hostname ) : return { 'status' : 'error' , 'error' : 'hostname argument required' } full = _get_known_hosts_file ( config = config , user = user ) if isinstance ( full , dict ) : return full if ( not os . path . isfile ( full ) ) : return { 'status' : 'error' , 'error' : 'Known hosts file {0} does not exist' . format ( full ) } ssh_hostname = _hostname_and_port_to_ssh_hostname ( hostname , port ) cmd = [ 'ssh-keygen' , '-R' , ssh_hostname , '-f' , full ] cmd_result = __salt__ [ 'cmd.run' ] ( cmd , python_shell = False ) if ( ( os . geteuid ( ) == 0 ) and user ) : uinfo = __salt__ [ 'user.info' ] ( user ) os . chown ( full , uinfo [ 'uid' ] , uinfo [ 'gid' ] ) return { 'status' : 'removed' , 'comment' : cmd_result }
remove all keys belonging to hostname from a known_hosts file .