Browse code

[stable-2.6] Temporarily revert c119d54

There were bugs in this that needed to be resolved. No time to get the
fix reviewed sufficiently for 2.6.0.

We'll get this into 2.7.0 and try to get this into 2.6.1 as well.

Will need the work done in https://github.com/ansible/ansible/pull/36218
when it does get merged.
(cherry picked from commit 5c614a59a66fc75b6e258053d3d17d151141e7f9)

Co-authored-by: Toshio Kuratomi <a.badger@gmail.com>

Toshio Kuratomi authored on 2018/06/16 03:36:07
Showing 6 changed files
... ...
@@ -107,9 +107,9 @@ from ansible.module_utils.six import b
107 107
 from ansible.module_utils._text import to_native
108 108
 
109 109
 
110
-def assemble_from_fragments(src_path, delimiter=None, compiled_regexp=None, ignore_hidden=False, tmpdir=None):
110
+def assemble_from_fragments(src_path, delimiter=None, compiled_regexp=None, ignore_hidden=False):
111 111
     ''' assemble a file from a directory of fragments '''
112
-    tmpfd, temp_path = tempfile.mkstemp(dir=tmpdir)
112
+    tmpfd, temp_path = tempfile.mkstemp()
113 113
     tmp = os.fdopen(tmpfd, 'wb')
114 114
     delimit_me = False
115 115
     add_newline = False
... ...
@@ -204,7 +204,7 @@ def main():
204 204
     if validate and "%s" not in validate:
205 205
         module.fail_json(msg="validate must contain %%s: %s" % validate)
206 206
 
207
-    path = assemble_from_fragments(src, delimiter, compiled_regexp, ignore_hidden, getattr(module, 'tmpdir', None))
207
+    path = assemble_from_fragments(src, delimiter, compiled_regexp, ignore_hidden)
208 208
     path_hash = module.sha1(path)
209 209
     result['checksum'] = path_hash
210 210
 
... ...
@@ -160,7 +160,7 @@ from ansible.module_utils._text import to_bytes
160 160
 
161 161
 def write_changes(module, contents, path):
162 162
 
163
-    tmpfd, tmpfile = tempfile.mkstemp(dir=getattr(module, 'tmpdir', None))
163
+    tmpfd, tmpfile = tempfile.mkstemp()
164 164
     f = os.fdopen(tmpfd, 'wb')
165 165
     f.write(contents)
166 166
     f.close()
... ...
@@ -154,7 +154,7 @@ from ansible.module_utils.basic import AnsibleModule
154 154
 
155 155
 def write_changes(module, contents, path):
156 156
 
157
-    tmpfd, tmpfile = tempfile.mkstemp(dir=getattr(module, 'tmpdir', None))
157
+    tmpfd, tmpfile = tempfile.mkstemp()
158 158
     f = os.fdopen(tmpfd, 'wb')
159 159
     f.write(contents)
160 160
     f.close()
... ...
@@ -49,8 +49,7 @@ options:
49 49
   tmp_dest:
50 50
     description:
51 51
       - Absolute path of where temporary file is downloaded to.
52
-      - When run on Ansible 2.5 or greater, path defaults to ansible's remote_tmp setting
53
-      - When run on Ansible prior to 2.5, it defaults to C(TMPDIR), C(TEMP) or C(TMP) env variables or a platform specific value.
52
+      - Defaults to C(TMPDIR), C(TEMP) or C(TMP) env variables or a platform specific value.
54 53
       - U(https://docs.python.org/2/library/tempfile.html#tempfile.tempdir)
55 54
     version_added: '2.1'
56 55
   force:
... ...
@@ -341,17 +340,18 @@ def url_get(module, url, dest, use_proxy, last_mod_time, force, timeout=10, head
341 341
                 module.fail_json(msg="%s is a file but should be a directory." % tmp_dest)
342 342
             else:
343 343
                 module.fail_json(msg="%s directory does not exist." % tmp_dest)
344
-    else:
345
-        tmp_dest = getattr(module, 'tmpdir', None)
346 344
 
347
-    fd, tempname = tempfile.mkstemp(dir=tmp_dest)
345
+        fd, tempname = tempfile.mkstemp(dir=tmp_dest)
346
+    else:
347
+        fd, tempname = tempfile.mkstemp()
348 348
 
349 349
     f = os.fdopen(fd, 'wb')
350 350
     try:
351 351
         shutil.copyfileobj(rsp, f)
352 352
     except Exception as e:
353 353
         os.remove(tempname)
354
-        module.fail_json(msg="failed to create temporary content file: %s" % to_native(e), exception=traceback.format_exc())
354
+        module.fail_json(msg="failed to create temporary content file: %s" % to_native(e),
355
+                         exception=traceback.format_exc())
355 356
     f.close()
356 357
     rsp.close()
357 358
     return tempname, info
... ...
@@ -252,7 +252,7 @@ JSON_CANDIDATES = ('text', 'json', 'javascript')
252 252
 
253 253
 def write_file(module, url, dest, content):
254 254
     # create a tempfile with some test content
255
-    fd, tmpsrc = tempfile.mkstemp(dir=getattr(module, 'tmpdir', None))
255
+    fd, tmpsrc = tempfile.mkstemp()
256 256
     f = open(tmpsrc, 'wb')
257 257
     try:
258 258
         f.write(content)
... ...
@@ -333,7 +333,7 @@ def ensure_yum_utils(module):
333 333
 def fetch_rpm_from_url(spec, module=None):
334 334
     # download package so that we can query it
335 335
     package_name, _ = os.path.splitext(str(spec.rsplit('/', 1)[1]))
336
-    package_file = tempfile.NamedTemporaryFile(dir=getattr(module, 'tmpdir', None), prefix=package_name, suffix='.rpm', delete=False)
336
+    package_file = tempfile.NamedTemporaryFile(prefix=package_name, suffix='.rpm', delete=False)
337 337
     module.add_cleanup_file(package_file.name)
338 338
     try:
339 339
         rsp, info = fetch_url(module, spec)