def rm_host(ip, alias):
 if (not has_pair(ip, alias)):
  return True
 hfn = _get_or_create_hostfile()
 with salt.utils.fopen(hfn) as fp_:
  lines = fp_.readlines()
 for ind in range(len(lines)):
  tmpline = lines[ind].strip()
  if (not tmpline):
   continue
  if tmpline.startswith('#'):
   continue
  comps = tmpline.split()
  if (comps[0] == ip):
   newline = '{0} DCTB  DCTB '.format(comps[0])
   for existing in comps[1:]:
    if (existing == alias):
     continue
    newline += ' {0}'.format(existing)
   if (newline.strip() == ip):
    lines[ind] = ''
   else:
    lines[ind] = (newline + os.linesep)
 with salt.utils.fopen(hfn, 'w+') as ofile:
  ofile.writelines(lines)
 return True

def rm_host ( ip , alias ) : if ( not has_pair ( ip , alias ) ) : return True hfn = _get_or_create_hostfile ( ) with salt . utils . fopen ( hfn ) as fp_ : lines = fp_ . readlines ( ) for ind in range ( len ( lines ) ) : tmpline = lines [ ind ] . strip ( ) if ( not tmpline ) : continue if tmpline . startswith ( '#' ) : continue comps = tmpline . split ( ) if ( comps [ 0 ] == ip ) : newline = '{0} DCTB  DCTB ' . format ( comps [ 0 ] ) for existing in comps [ 1 : ] : if ( existing == alias ) : continue newline += ' {0}' . format ( existing ) if ( newline . strip ( ) == ip ) : lines [ ind ] = '' else : lines [ ind ] = ( newline + os . linesep ) with salt . utils . fopen ( hfn , 'w+' ) as ofile : ofile . writelines ( lines ) return True
remove a host entry from the hosts file cli example: .