From fa6ce54011ffd7974d5969fb39d033c3f3d72a89 Mon Sep 17 00:00:00 2001 From: Nicolas Porcel Date: Mon, 7 Aug 2017 10:48:30 +0200 Subject: [PATCH] Fix yum with rpm file or url when state=latest (#27775) --- lib/ansible/modules/packaging/os/yum.py | 29 +++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/ansible/modules/packaging/os/yum.py b/lib/ansible/modules/packaging/os/yum.py index 9387b1ceab..b4d18b6875 100644 --- a/lib/ansible/modules/packaging/os/yum.py +++ b/lib/ansible/modules/packaging/os/yum.py @@ -925,6 +925,35 @@ def latest(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos, in pkgs['update'].append(spec) will_update.add(spec) continue + + # check if pkgspec is installed (if possible for idempotence) + # localpkg + elif spec.endswith('.rpm') and '://' not in spec: + if 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) + res['rc'] = 127 # Ensure the task fails in with-loop + module.fail_json(**res) + + # get the pkg name-v-r.arch + nvra = local_nvra(module, spec) + + # local rpm files can't be updated + if not is_installed(module, repoq, nvra, conf_file, en_repos=en_repos, dis_repos=dis_repos, installroot=installroot): + pkgs['install'].append(spec) + continue + + # URL + elif '://' in spec: + # download package so that we can check if it's already installed + package = fetch_rpm_from_url(spec, module=module) + nvra = local_nvra(module, package) + + # local rpm files can't be updated + if not is_installed(module, repoq, nvra, conf_file, en_repos=en_repos, dis_repos=dis_repos, installroot=installroot): + pkgs['install'].append(package) + continue + # dep/pkgname - find it else: if is_installed(module, repoq, spec, conf_file, en_repos=en_repos, dis_repos=dis_repos, installroot=installroot):