def host_keys(keydir=None, private=True):
 if (not keydir):
  if (__grains__['kernel'] == 'Linux'):
   keydir = '/etc/ssh'
  else:
   raise SaltInvocationError('ssh.host_keys: Please specify a keydir')
 keys = {}
 for fn_ in os.listdir(keydir):
  if fn_.startswith('ssh_host_'):
   if ((fn_.endswith('.pub') is False) and (private is False)):
    log.info('Skipping private key file {0} as private is set to False'.format(fn_))
    continue
   top = fn_.split('.')
   comps = top[0].split('_')
   kname = comps[2]
   if (len(top) > 1):
    kname += '.{0}'.format(top[1])
   try:
    with salt.utils.fopen(os.path.join(keydir, fn_), 'r') as _fh:
     keys[kname] = _fh.readline()
     if (keys[kname] != 'SSH PRIVATE KEY FILE FORMAT 1.1\n'):
      keys[kname] += _fh.read()
     keys[kname] = keys[kname].strip()
   except (IOError, OSError):
    keys[kname] = ''
 return keys

def host_keys ( keydir = None , private = True ) : if ( not keydir ) : if ( __grains__ [ 'kernel' ] == 'Linux' ) : keydir = '/etc/ssh' else : raise SaltInvocationError ( 'ssh.host_keys: Please specify a keydir' ) keys = { } for fn_ in os . listdir ( keydir ) : if fn_ . startswith ( 'ssh_host_' ) : if ( ( fn_ . endswith ( '.pub' ) is False ) and ( private is False ) ) : log . info ( 'Skipping private key file {0} as private is set to False' . format ( fn_ ) ) continue top = fn_ . split ( '.' ) comps = top [ 0 ] . split ( '_' ) kname = comps [ 2 ] if ( len ( top ) > 1 ) : kname += '.{0}' . format ( top [ 1 ] ) try : with salt . utils . fopen ( os . path . join ( keydir , fn_ ) , 'r' ) as _fh : keys [ kname ] = _fh . readline ( ) if ( keys [ kname ] != 'SSH PRIVATE KEY FILE FORMAT 1.1\n' ) : keys [ kname ] += _fh . read ( ) keys [ kname ] = keys [ kname ] . strip ( ) except ( IOError , OSError ) : keys [ kname ] = '' return keys
return the minions host keys cli example: .