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

apt: fix always changed when using deb file on Debian 8 (#3541)

Extends d74e82a3f1e3293ffb70c172e5bb2b6e1ff6dbcc with also support
downgrade.
This commit is contained in:
René Moser 2016-05-06 09:17:04 +02:00 committed by Matt Clay
parent bc39f8c42e
commit 326f7166c0

View file

@ -469,6 +469,14 @@ def install(m, pkgspec, cache, upgrade=False, default_release=None,
else:
return (True, dict(changed=False))
def get_field_of_deb(m, deb_file, field="Version"):
cmd_dpkg = m.get_bin_path("dpkg", True)
cmd = cmd_dpkg + " --field %s %s" % (deb_file, field)
rc, stdout, stderr = m.run_command(cmd)
if rc != 0:
m.fail_json(msg="%s failed" % cmd, stdout=stdout, stderr=stderr)
return stdout.strip('\n')
def install_deb(m, debs, cache, force, install_recommends, allow_unauthenticated, dpkg_options):
changed=False
deps_to_install = []
@ -476,10 +484,17 @@ def install_deb(m, debs, cache, force, install_recommends, allow_unauthenticated
for deb_file in debs.split(','):
try:
pkg = apt.debfile.DebPackage(deb_file)
# Check if it's already installed
if pkg.compare_to_version_in_cache() == pkg.VERSION_SAME:
continue
pkg_name = get_field_of_deb(m, deb_file, "Package")
pkg_version = get_field_of_deb(m, deb_file, "Version")
try:
installed_pkg = apt.Cache()[pkg_name]
installed_version = installed_pkg.installed.version
if package_version_compare(pkg_version, installed_version) == 0:
# Does not need to down-/upgrade, move on to next package
continue
except Exception, e:
# Must not be installed, continue with installation
pass
# Check if package is installable
if not pkg.check() and not force:
m.fail_json(msg=pkg._failure_string)
@ -659,7 +674,7 @@ def main():
cache_valid_time = dict(type='int'),
purge = dict(default=False, type='bool'),
package = dict(default=None, aliases=['pkg', 'name'], type='list'),
deb = dict(default=None),
deb = dict(default=None, type='path'),
default_release = dict(default=None, aliases=['default-release']),
install_recommends = dict(default=None, aliases=['install-recommends'], type='bool'),
force = dict(default='no', type='bool'),