diff --git a/lib/ansible/modules/web_infrastructure/jenkins_plugin.py b/lib/ansible/modules/web_infrastructure/jenkins_plugin.py index 832dbe060a..41568357f1 100644 --- a/lib/ansible/modules/web_infrastructure/jenkins_plugin.py +++ b/lib/ansible/modules/web_infrastructure/jenkins_plugin.py @@ -575,19 +575,10 @@ class JenkinsPlugin(object): # Write the updates file update_fd, updates_file = tempfile.mkstemp() + os.write(update_fd, r.read()) try: - fd = open(updates_file, 'wb') - except IOError: - e = get_exception() - self.module.fail_json( - msg="Cannot open the tmp updates file %s." % updates_file, - details=str(e)) - - fd.write(r.read()) - - try: - fd.close() + os.close(update_fd) except IOError: e = get_exception() self.module.fail_json( @@ -651,25 +642,15 @@ class JenkinsPlugin(object): def _write_file(self, f, data): # Store the plugin into a temp file and then move it - tmp_f_tuple, tmp_f = tempfile.mkstemp() - - try: - fd = open(tmp_f, 'wb') - except IOError: - e = get_exception() - self.module.fail_json( - msg='Cannot open the temporal plugin file %s.' % tmp_f, - details=str(e)) + tmp_f_fd, tmp_f = tempfile.mkstemp() if isinstance(data, str): - d = data + os.write(tmp_f_fd, data) else: - d = data.read() - - fd.write(d) + os.write(tmp_f_fd, data.read()) try: - fd.close() + os.close(tmp_f_fd) except IOError: e = get_exception() self.module.fail_json(