def file(name, source_hash='', source_hash_name=None, user='root', template=None, context=None, replace=True, defaults=None, backup='', **kwargs):
 mode = '0600'
 try:
  group = __salt__['user.info'](user)['groups'][0]
 except Exception:
  ret = {'changes': {}, 'comment': 'Could not identify group for user {0}'.format(user), 'name': name, 'result': False}
  return ret
 cron_path = salt.utils.files.mkstemp()
 with salt.utils.fopen(cron_path, 'w+') as fp_:
  raw_cron = __salt__['cron.raw_cron'](user)
  if (not raw_cron.endswith('\n')):
   raw_cron = '{0}\n'.format(raw_cron)
  fp_.write(raw_cron)
 ret = {'changes': {}, 'comment': '', 'name': name, 'result': True}
 source = name
 if ((not replace) and (os.stat(cron_path).st_size > 0)):
  ret['comment'] = 'User {0} already has a crontab. No changes made'.format(user)
  os.unlink(cron_path)
  return ret
 if __opts__['test']:
  fcm = __salt__['file.check_managed'](cron_path, source, source_hash, source_hash_name, user, group, mode, template, context, defaults, __env__, **kwargs)
  (ret['result'], ret['comment']) = fcm
  os.unlink(cron_path)
  return ret
 (source, source_hash) = __salt__['file.source_list'](source, source_hash, __env__)
 try:
  (sfn, source_sum, comment) = __salt__['file.get_managed'](cron_path, template, source, source_hash, source_hash_name, user, group, mode, __env__, context, defaults, False, **kwargs)
 except Exception as exc:
  ret['result'] = False
  ret['changes'] = {}
  ret['comment'] = 'Unable to manage file: {0}'.format(exc)
  return ret
 if comment:
  ret['comment'] = comment
  ret['result'] = False
  os.unlink(cron_path)
  return ret
 try:
  ret = __salt__['file.manage_file'](cron_path, sfn, ret, source, source_sum, user, group, mode, __env__, backup)
 except Exception as exc:
  ret['result'] = False
  ret['changes'] = {}
  ret['comment'] = 'Unable to manage file: {0}'.format(exc)
  return ret
 cron_ret = None
 if ('diff' in ret['changes']):
  cron_ret = __salt__['cron.write_cron_file_verbose'](user, cron_path)
  if (cron_ret['retcode'] == 0):
   ret['comment'] = 'Crontab for user {0} was updated'.format(user)
   ret['result'] = True
   ret['changes'] = ret['changes']['diff']
  else:
   ret['comment'] = 'Unable to update user {0} crontab {1}. Error: {2}'.format(user, cron_path, cron_ret['stderr'])
   ret['result'] = False
   ret['changes'] = {}
 elif ret['result']:
  ret['comment'] = 'Crontab for user {0} is in the correct state'.format(user)
  ret['changes'] = {}
 os.unlink(cron_path)
 return ret

def file ( name , source_hash = '' , source_hash_name = None , user = 'root' , template = None , context = None , replace = True , defaults = None , backup = '' , ** kwargs ) : mode = '0600' try : group = __salt__ [ 'user.info' ] ( user ) [ 'groups' ] [ 0 ] except Exception : ret = { 'changes' : { } , 'comment' : 'Could not identify group for user {0}' . format ( user ) , 'name' : name , 'result' : False } return ret cron_path = salt . utils . files . mkstemp ( ) with salt . utils . fopen ( cron_path , 'w+' ) as fp_ : raw_cron = __salt__ [ 'cron.raw_cron' ] ( user ) if ( not raw_cron . endswith ( '\n' ) ) : raw_cron = '{0}\n' . format ( raw_cron ) fp_ . write ( raw_cron ) ret = { 'changes' : { } , 'comment' : '' , 'name' : name , 'result' : True } source = name if ( ( not replace ) and ( os . stat ( cron_path ) . st_size > 0 ) ) : ret [ 'comment' ] = 'User {0} already has a crontab. No changes made' . format ( user ) os . unlink ( cron_path ) return ret if __opts__ [ 'test' ] : fcm = __salt__ [ 'file.check_managed' ] ( cron_path , source , source_hash , source_hash_name , user , group , mode , template , context , defaults , __env__ , ** kwargs ) ( ret [ 'result' ] , ret [ 'comment' ] ) = fcm os . unlink ( cron_path ) return ret ( source , source_hash ) = __salt__ [ 'file.source_list' ] ( source , source_hash , __env__ ) try : ( sfn , source_sum , comment ) = __salt__ [ 'file.get_managed' ] ( cron_path , template , source , source_hash , source_hash_name , user , group , mode , __env__ , context , defaults , False , ** kwargs ) except Exception as exc : ret [ 'result' ] = False ret [ 'changes' ] = { } ret [ 'comment' ] = 'Unable to manage file: {0}' . format ( exc ) return ret if comment : ret [ 'comment' ] = comment ret [ 'result' ] = False os . unlink ( cron_path ) return ret try : ret = __salt__ [ 'file.manage_file' ] ( cron_path , sfn , ret , source , source_sum , user , group , mode , __env__ , backup ) except Exception as exc : ret [ 'result' ] = False ret [ 'changes' ] = { } ret [ 'comment' ] = 'Unable to manage file: {0}' . format ( exc ) return ret cron_ret = None if ( 'diff' in ret [ 'changes' ] ) : cron_ret = __salt__ [ 'cron.write_cron_file_verbose' ] ( user , cron_path ) if ( cron_ret [ 'retcode' ] == 0 ) : ret [ 'comment' ] = 'Crontab for user {0} was updated' . format ( user ) ret [ 'result' ] = True ret [ 'changes' ] = ret [ 'changes' ] [ 'diff' ] else : ret [ 'comment' ] = 'Unable to update user {0} crontab {1}. Error: {2}' . format ( user , cron_path , cron_ret [ 'stderr' ] ) ret [ 'result' ] = False ret [ 'changes' ] = { } elif ret [ 'result' ] : ret [ 'comment' ] = 'Crontab for user {0} is in the correct state' . format ( user ) ret [ 'changes' ] = { } os . unlink ( cron_path ) return ret
a dynamically retrieved file .