def parse_hosts(hostsfile='/etc/hosts', hosts=None):
 if (not hosts):
  try:
   with salt.utils.fopen(hostsfile, 'r') as fp_:
    hosts = fp_.read()
  except Exception:
   return 'Error: hosts data was not found'
 hostsdict = {}
 for line in hosts.splitlines():
  if (not line):
   continue
  if line.startswith('#'):
   continue
  comps = line.split()
  ip = comps[0]
  aliases = comps[1:]
  hostsdict.setdefault(ip, []).extend(aliases)
 return hostsdict

def parse_hosts ( hostsfile = '/etc/hosts' , hosts = None ) : if ( not hosts ) : try : with salt . utils . fopen ( hostsfile , 'r' ) as fp_ : hosts = fp_ . read ( ) except Exception : return 'Error: hosts data was not found' hostsdict = { } for line in hosts . splitlines ( ) : if ( not line ) : continue if line . startswith ( '#' ) : continue comps = line . split ( ) ip = comps [ 0 ] aliases = comps [ 1 : ] hostsdict . setdefault ( ip , [ ] ) . extend ( aliases ) return hostsdict
parse /etc/hosts file .