From b710b40a0c91f6352a4283401b2298d271716382 Mon Sep 17 00:00:00 2001 From: Adam Miller Date: Fri, 14 Dec 2018 13:44:40 -0600 Subject: [PATCH] Fix yum/dnf handling of URIs that don't end in .rpm (#49912) Fixes #49727 Signed-off-by: Adam Miller (cherry picked from commit 0eabb8097b0475ba5e8d5fba7fc5e1fad0934f30) --- lib/ansible/modules/packaging/os/dnf.py | 7 ++++--- lib/ansible/modules/packaging/os/yum.py | 8 +++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/packaging/os/dnf.py b/lib/ansible/modules/packaging/os/dnf.py index 73e40ba6cc6..6483fe43dbc 100644 --- a/lib/ansible/modules/packaging/os/dnf.py +++ b/lib/ansible/modules/packaging/os/dnf.py @@ -726,9 +726,10 @@ class DnfModule(YumDnf): already_loaded_comps = False # Only load this if necessary, it's slow for name in self.names: - if name.endswith(".rpm"): - if '://' in name: - name = self.fetch_rpm_from_url(name) + if '://' in name: + name = self.fetch_rpm_from_url(name) + filenames.append(name) + elif name.endswith(".rpm"): filenames.append(name) elif name.startswith("@") or ('/' in name): if not already_loaded_comps: diff --git a/lib/ansible/modules/packaging/os/yum.py b/lib/ansible/modules/packaging/os/yum.py index 790c2779c01..4231542124d 100644 --- a/lib/ansible/modules/packaging/os/yum.py +++ b/lib/ansible/modules/packaging/os/yum.py @@ -872,7 +872,7 @@ class YumModule(YumDnf): downgrade_candidate = False # check if pkgspec is installed (if possible for idempotence) - if spec.endswith('.rpm'): + if spec.endswith('.rpm') or '://' in spec: if '://' not in spec and not os.path.exists(spec): res['msg'] += "No RPM file matching '%s' found on system" % spec res['results'].append("No RPM file matching '%s' found on system" % spec) @@ -882,6 +882,12 @@ class YumModule(YumDnf): if '://' in spec: with self.set_env_proxy(): package = self.fetch_rpm_from_url(spec) + if not package.endswith('.rpm'): + # yum requires a local file to have the extension of .rpm and we + # can not guarantee that from an URL (redirects, proxies, etc) + new_package_path = '%s.rpm' % package + os.rename(package, new_package_path) + package = new_package_path else: package = spec