@ -2273,20 +2273,29 @@ class AnsibleModule(object):
native_dest_dir = b_dest_dir
native_suffix = os . path . basename ( b_dest )
native_prefix = b ( ' .ansible_tmp ' )
error_msg = None
tmp_dest_name = None
try :
tmp_dest_fd , tmp_dest_name = tempfile . mkstemp ( prefix = native_prefix , dir = native_dest_dir , suffix = native_suffix )
except ( OSError , IOError ) :
e = get_exception ( )
self . fail_json ( msg = ' The destination directory ( %s ) is not writable by the current user. Error was: %s ' % ( os . path . dirname ( dest ) , e ) )
error_msg = ' The destination directory ( %s ) is not writable by the current user. Error was: %s ' % ( os . path . dirname ( dest ) , e )
except TypeError :
# We expect that this is happening because python3.4.x and
# below can't handle byte strings in mkstemp(). Traceback
# would end in something like:
# file = _os.path.join(dir, pre + name + suf)
# TypeError: can't concat bytes to str
self . fail_json ( msg = ' Failed creating temp file for atomic move. This usually happens when using Python3 less than Python3.5. '
' Please use Python2.x or Python3.5 or greater. ' , exception = traceback . format_exc ( ) )
error_msg = ( ' Failed creating temp file for atomic move. This usually happens when using Python3 less than Python3.5. '
' Please use Python2.x or Python3.5 or greater. ' )
finally :
if error_msg :
if unsafe_writes :
self . _unsafe_writes ( b_src , b_dest )
else :
self . fail_json ( msg = error_msg , exception = traceback . format_exc ( ) )
if tmp_dest_name :
b_tmp_dest_name = to_bytes ( tmp_dest_name , errors = ' surrogate_or_strict ' )
try :