@ -553,34 +553,38 @@ def execute_touch(path, follow, timestamps):
mtime = get_timestamp_for_time ( timestamps [ ' modification_time ' ] , timestamps [ ' modification_time_format ' ] )
mtime = get_timestamp_for_time ( timestamps [ ' modification_time ' ] , timestamps [ ' modification_time_format ' ] )
atime = get_timestamp_for_time ( timestamps [ ' access_time ' ] , timestamps [ ' access_time_format ' ] )
atime = get_timestamp_for_time ( timestamps [ ' access_time ' ] , timestamps [ ' access_time_format ' ] )
if not module . check_mode :
# If the file did not already exist
if prev_state == ' absent ' :
if prev_state == ' absent ' :
# Create an empty file if the filename did not already exist
# if we are in check mode and the file is absent
try :
# we can set the changed status to True and return
open ( b_path , ' wb ' ) . close ( )
if module . check_mode :
changed = True
result [ ' changed ' ] = True
except ( OSError , IOError ) as e :
return result
raise AnsibleModuleError ( results = { ' msg ' : ' Error, could not touch target: %s '
# Create an empty file
% to_native ( e , nonstring = ' simplerepr ' ) ,
' path ' : path } )
# Update the attributes on the file
diff = initial_diff ( path , ' touch ' , prev_state )
file_args = module . load_file_common_arguments ( module . params )
try :
try :
changed = module . set_fs_attributes_if_different ( file_args , changed , diff , expand = False )
open ( b_path , ' wb ' ) . close ( )
changed | = update_timestamp_for_file ( file_args [ ' path ' ] , mtime , atime , diff )
changed = True
except SystemExit as e :
except ( OSError , IOError ) as e :
if e . code : # this is the exit code passed to sys.exit, not a constant -- pylint: disable=using-constant-test
raise AnsibleModuleError ( results = { ' msg ' : ' Error, could not touch target: %s '
# We take this to mean that fail_json() was called from
% to_native ( e , nonstring = ' simplerepr ' ) ,
# somewhere in basic.py
' path ' : path } )
if prev_state == ' absent ' :
# Update the attributes on the file
# If we just created the file we can safely remove it
diff = initial_diff ( path , ' touch ' , prev_state )
os . remove ( b_path )
file_args = module . load_file_common_arguments ( module . params )
raise
try :
changed = module . set_fs_attributes_if_different ( file_args , changed , diff , expand = False )
result [ ' changed ' ] = changed
changed | = update_timestamp_for_file ( file_args [ ' path ' ] , mtime , atime , diff )
result [ ' diff ' ] = diff
except SystemExit as e :
if e . code : # this is the exit code passed to sys.exit, not a constant -- pylint: disable=using-constant-test
# We take this to mean that fail_json() was called from
# somewhere in basic.py
if prev_state == ' absent ' :
# If we just created the file we can safely remove it
os . remove ( b_path )
raise
result [ ' changed ' ] = changed
result [ ' diff ' ] = diff
return result
return result