diff options
author | Jonathan Mainguy <jon@soh.re> | 2015-05-22 23:16:56 -0400 |
---|---|---|
committer | Toshio Kuratomi <toshio@fedoraproject.org> | 2015-05-29 13:44:38 -0700 |
commit | 3a14b998f34eddc43d4027815186757e74dabfc7 (patch) | |
tree | 0e210de440591bf15e1fe0136e24f50f9c0378c4 | |
parent | 7f18a6513fc056660ed75548224a80df4b974317 (diff) | |
download | ansible-modules-core-3a14b998f34eddc43d4027815186757e74dabfc7.tar.gz |
add :// url support for EL 5
-rw-r--r-- | packaging/os/yum.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/packaging/os/yum.py b/packaging/os/yum.py index a92d7134..8019c9fc 100644 --- a/packaging/os/yum.py +++ b/packaging/os/yum.py @@ -27,6 +27,11 @@ import os import yum import rpm import syslog +import platform +import tempfile +import shutil +from ansible.module_utils.urls import * +from distutils.version import LooseVersion try: from yum.misc import find_unfinished_transactions, find_ts_remaining @@ -480,6 +485,7 @@ def install(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos): res['msg'] = '' res['rc'] = 0 res['changed'] = False + tempdir = tempfile.mkdtemp() for spec in items: pkg = None @@ -502,6 +508,21 @@ def install(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos): # URL elif '://' in spec: pkg = spec + # Check if Enterprise Linux 5 or less, as yum on those versions do not support installing via url + distribution_version = get_distribution_version() + distribution = platform.dist() + if distribution[0] == "redhat" and LooseVersion(distribution_version) < LooseVersion("6"): + package = os.path.join(tempdir, str(pkg.rsplit('/', 1)[1])) + try: + rsp, info = fetch_url(module, pkg) + data = rsp.read() + f = open(package, 'w') + f.write(data) + f.close() + pkg = package + except Exception, e: + shutil.rmtree(tempdir) + module.fail_json(msg="Failure downloading %s, %s" % (spec, e)) #groups :( elif spec.startswith('@'): @@ -563,6 +584,11 @@ def install(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos): cmd = yum_basecmd + ['install', pkg] if module.check_mode: + # Remove rpms downloaded for EL5 via url + try: + shutil.rmtree(tempdir) + except Exception, e: + module.fail_json(msg="Failure deleting temp directory %s, %s" % (tempdir, e)) module.exit_json(changed=True) changed = True @@ -594,6 +620,12 @@ def install(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos): # accumulate any changes res['changed'] |= changed + # Remove rpms downloaded for EL5 via url + try: + shutil.rmtree(tempdir) + except Exception, e: + module.fail_json(msg="Failure deleting temp directory %s, %s" % (tempdir, e)) + module.exit_json(**res) |