1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Clean downloaded rpm files after install (#20594)

This commit is contained in:
Nicolas Porcel 2017-08-07 09:17:49 +02:00 committed by Martin Krizek
parent d2f9160bc1
commit 616d5ddc93

View file

@ -290,24 +290,23 @@ def ensure_yum_utils(module):
def fetch_rpm_from_url(spec, module=None):
# download package so that we can query it
tempdir = tempfile.mkdtemp()
package = os.path.join(tempdir, str(spec.rsplit('/', 1)[1]))
package_name, _ = os.path.splitext(str(spec.rsplit('/', 1)[1]))
package_file = tempfile.NamedTemporaryFile(prefix=package_name, suffix='.rpm', delete=False)
module.add_cleanup_file(package_file.name)
try:
rsp, info = fetch_url(module, spec)
if not rsp:
module.fail_json(msg="Failure downloading %s, %s" % (spec, info['msg']))
f = open(package, 'w')
data = rsp.read(BUFSIZE)
while data:
f.write(data)
package_file.write(data)
data = rsp.read(BUFSIZE)
f.close()
package_file.close()
except Exception:
e = get_exception()
shutil.rmtree(tempdir)
if module:
module.fail_json(msg="Failure downloading %s, %s" % (spec, e))
return package
return package_file.name
def po_to_nevra(po):
@ -478,13 +477,6 @@ def what_provides(module, repoq, req_spec, conf_file, qf=def_qf, en_repos=None,
if dis_repos is None:
dis_repos = []
if req_spec.endswith('.rpm') and '://' not in req_spec:
return req_spec
elif '://' in req_spec:
local_path = fetch_rpm_from_url(req_spec, module=module)
return local_path
if not repoq:
pkgs = []
@ -655,7 +647,6 @@ def install(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos, i
res['msg'] = ''
res['rc'] = 0
res['changed'] = False
tempdir = tempfile.mkdtemp()
for spec in items:
pkg = None
@ -754,13 +745,6 @@ def install(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos, i
cmd = yum_basecmd + ['install'] + pkgs
if module.check_mode:
# Remove rpms downloaded for EL5 via url
try:
shutil.rmtree(tempdir)
except Exception:
e = get_exception()
module.fail_json(msg="Failure deleting temp directory %s, %s" % (tempdir, e))
module.exit_json(changed=True, results=res['results'], changes=dict(installed=pkgs))
changed = True
@ -794,13 +778,6 @@ def install(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos, i
# Record change
res['changed'] = changed
# Remove rpms downloaded for EL5 via url
try:
shutil.rmtree(tempdir)
except Exception:
e = get_exception()
module.fail_json(msg="Failure deleting temp directory %s, %s" % (tempdir, e))
return res