From 600a4657b43894454fa5109d1b77adf65d1b0ed7 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Thu, 7 Aug 2014 00:07:55 -0500 Subject: [PATCH] Catch error in atomic_move when creating temporary file Fixes #8480 --- lib/ansible/module_utils/basic.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py index 3a541d67d6..4d32d04ce5 100644 --- a/lib/ansible/module_utils/basic.py +++ b/lib/ansible/module_utils/basic.py @@ -1132,8 +1132,11 @@ class AnsibleModule(object): dest_dir = os.path.dirname(dest) dest_file = os.path.basename(dest) - tmp_dest = tempfile.NamedTemporaryFile( - prefix=".ansible_tmp", dir=dest_dir, suffix=dest_file) + try: + tmp_dest = tempfile.NamedTemporaryFile( + prefix=".ansible_tmp", dir=dest_dir, suffix=dest_file) + except (OSError, IOError), e: + self.fail_json(msg='The destination directory (%s) is not writable by the current user.' % dest_dir) try: # leaves tmp file behind when sudo and not root if switched_user and os.getuid() != 0: