def set_auth_key_from_file(user, source, config='.ssh/authorized_keys', saltenv='base'):
 lfile = __salt__['cp.cache_file'](source, saltenv)
 if (not os.path.isfile(lfile)):
  raise CommandExecutionError('Failed to pull key file from salt file server')
 s_keys = _validate_keys(lfile)
 if (not s_keys):
  err = 'No keys detected in {0}. Is file properly formatted?'.format(source)
  log.error(err)
  __context__['ssh_auth.error'] = err
  return 'fail'
 else:
  rval = ''
  for key in s_keys:
   rval += set_auth_key(user, key, s_keys[key]['enc'], s_keys[key]['comment'], s_keys[key]['options'], config, list(s_keys.keys()))
  if ('fail' in rval):
   return 'fail'
  elif ('replace' in rval):
   return 'replace'
  elif ('new' in rval):
   return 'new'
  else:
   return 'no change'

def set_auth_key_from_file ( user , source , config = '.ssh/authorized_keys' , saltenv = 'base' ) : lfile = __salt__ [ 'cp.cache_file' ] ( source , saltenv ) if ( not os . path . isfile ( lfile ) ) : raise CommandExecutionError ( 'Failed to pull key file from salt file server' ) s_keys = _validate_keys ( lfile ) if ( not s_keys ) : err = 'No keys detected in {0}. Is file properly formatted?' . format ( source ) log . error ( err ) __context__ [ 'ssh_auth.error' ] = err return 'fail' else : rval = '' for key in s_keys : rval += set_auth_key ( user , key , s_keys [ key ] [ 'enc' ] , s_keys [ key ] [ 'comment' ] , s_keys [ key ] [ 'options' ] , config , list ( s_keys . keys ( ) ) ) if ( 'fail' in rval ) : return 'fail' elif ( 'replace' in rval ) : return 'replace' elif ( 'new' in rval ) : return 'new' else : return 'no change'
add a key to the authorized_keys file .