@ -99,8 +99,13 @@ JINJA2_END_TOKENS = frozenset(('variable_end', 'block_end', 'comment_end', 'raw_
RANGE_TYPE = type ( range ( 0 ) )
RANGE_TYPE = type ( range ( 0 ) )
def generate_ansible_template_vars ( path , dest_path = None ) :
def generate_ansible_template_vars ( path , fullpath = None , dest_path = None ) :
b_path = to_bytes ( path )
if fullpath is None :
b_path = to_bytes ( path )
else :
b_path = to_bytes ( fullpath )
try :
try :
template_uid = pwd . getpwuid ( os . stat ( b_path ) . st_uid ) . pw_name
template_uid = pwd . getpwuid ( os . stat ( b_path ) . st_uid ) . pw_name
except ( KeyError , TypeError ) :
except ( KeyError , TypeError ) :
@ -111,11 +116,15 @@ def generate_ansible_template_vars(path, dest_path=None):
' template_path ' : path ,
' template_path ' : path ,
' template_mtime ' : datetime . datetime . fromtimestamp ( os . path . getmtime ( b_path ) ) ,
' template_mtime ' : datetime . datetime . fromtimestamp ( os . path . getmtime ( b_path ) ) ,
' template_uid ' : to_text ( template_uid ) ,
' template_uid ' : to_text ( template_uid ) ,
' template_fullpath ' : os . path . abspath ( path ) ,
' template_run_date ' : datetime . datetime . now ( ) ,
' template_run_date ' : datetime . datetime . now ( ) ,
' template_destpath ' : to_native ( dest_path ) if dest_path else None ,
' template_destpath ' : to_native ( dest_path ) if dest_path else None ,
}
}
if fullpath is None :
temp_vars [ ' template_fullpath ' ] = os . path . abspath ( path )
else :
temp_vars [ ' template_fullpath ' ] = fullpath
managed_default = C . DEFAULT_MANAGED_STR
managed_default = C . DEFAULT_MANAGED_STR
managed_str = managed_default . format (
managed_str = managed_default . format (
host = temp_vars [ ' template_host ' ] ,
host = temp_vars [ ' template_host ' ] ,