Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct handling of "onlyupgrade" option in apt module - fixes #30638 #31577

Merged
merged 1 commit into from
Apr 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 14 additions & 12 deletions lib/ansible/modules/packaging/os/apt.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,20 +350,21 @@ def package_status(m, pkgname, version, cache, state):
if provided_packages:
is_installed = False
upgradable = False
version_ok = False
# when virtual package providing only one package, look up status of target package
if cache.is_virtual_package(pkgname) and len(provided_packages) == 1:
package = provided_packages[0]
installed, upgradable, has_files = package_status(m, package.name, version, cache, state='install')
installed, version_ok, upgradable, has_files = package_status(m, package.name, version, cache, state='install')
if installed:
is_installed = True
return is_installed, upgradable, False
return is_installed, version_ok, upgradable, False
m.fail_json(msg="No package matching '%s' is available" % pkgname)
except AttributeError:
# python-apt version too old to detect virtual packages
# mark as upgradable and let apt-get install deal with it
return False, True, False
return False, False, True, False
else:
return False, False, False
return False, False, False, False
try:
has_files = len(pkg.installed_files) > 0
except UnicodeDecodeError:
Expand All @@ -381,6 +382,7 @@ def package_status(m, pkgname, version, cache, state):
# assume older version of python-apt is installed
package_is_installed = pkg.isInstalled

version_is_installed = package_is_installed
if version:
versions = package_versions(pkgname, pkg, cache._cache)
avail_upgrades = fnmatch.filter(versions, version)
Expand All @@ -391,8 +393,8 @@ def package_status(m, pkgname, version, cache, state):
except AttributeError:
installed_version = pkg.installedVersion

# Only claim the package is installed if the version is matched as well
package_is_installed = fnmatch.fnmatch(installed_version, version)
# check if the version is matched as well
version_is_installed = fnmatch.fnmatch(installed_version, version)

# Only claim the package is upgradable if a candidate matches the version
package_is_upgradable = False
Expand All @@ -409,7 +411,7 @@ def package_status(m, pkgname, version, cache, state):
# assume older version of python-apt is installed
package_is_upgradable = pkg.isUpgradable

return package_is_installed, package_is_upgradable, has_files
return package_is_installed, version_is_installed, package_is_upgradable, has_files


def expand_dpkg_options(dpkg_options_compressed):
Expand Down Expand Up @@ -519,10 +521,10 @@ def install(m, pkgspec, cache, upgrade=False, default_release=None,

name, version = package_split(package)
package_names.append(name)
installed, upgradable, has_files = package_status(m, name, version, cache, state='install')
if (not installed and not only_upgrade) or (upgrade and upgradable):
installed, installed_version, upgradable, has_files = package_status(m, name, version, cache, state='install')
if (not installed and not only_upgrade) or (installed and not installed_version) or (upgrade and upgradable):
pkg_list.append("'%s'" % package)
if installed and upgradable and version:
if installed_version and upgradable and version:
# This happens when the package is installed, a newer version is
# available, and the version is a wildcard that matches both
#
Expand Down Expand Up @@ -684,8 +686,8 @@ def remove(m, pkgspec, cache, purge=False, force=False,
pkgspec = expand_pkgspec_from_fnmatches(m, pkgspec, cache)
for package in pkgspec:
name, version = package_split(package)
installed, upgradable, has_files = package_status(m, name, version, cache, state='remove')
if installed or (has_files and purge):
installed, installed_version, upgradable, has_files = package_status(m, name, version, cache, state='remove')
if installed_version or (has_files and purge):
pkg_list.append("'%s'" % package)
packages = ' '.join(pkg_list)

Expand Down