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:
parent
bc39f8c42e
commit
326f7166c0
1 changed files with 20 additions and 5 deletions
|
@ -469,6 +469,14 @@ def install(m, pkgspec, cache, upgrade=False, default_release=None,
|
||||||
else:
|
else:
|
||||||
return (True, dict(changed=False))
|
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):
|
def install_deb(m, debs, cache, force, install_recommends, allow_unauthenticated, dpkg_options):
|
||||||
changed=False
|
changed=False
|
||||||
deps_to_install = []
|
deps_to_install = []
|
||||||
|
@ -476,10 +484,17 @@ def install_deb(m, debs, cache, force, install_recommends, allow_unauthenticated
|
||||||
for deb_file in debs.split(','):
|
for deb_file in debs.split(','):
|
||||||
try:
|
try:
|
||||||
pkg = apt.debfile.DebPackage(deb_file)
|
pkg = apt.debfile.DebPackage(deb_file)
|
||||||
|
pkg_name = get_field_of_deb(m, deb_file, "Package")
|
||||||
# Check if it's already installed
|
pkg_version = get_field_of_deb(m, deb_file, "Version")
|
||||||
if pkg.compare_to_version_in_cache() == pkg.VERSION_SAME:
|
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
|
continue
|
||||||
|
except Exception, e:
|
||||||
|
# Must not be installed, continue with installation
|
||||||
|
pass
|
||||||
# Check if package is installable
|
# Check if package is installable
|
||||||
if not pkg.check() and not force:
|
if not pkg.check() and not force:
|
||||||
m.fail_json(msg=pkg._failure_string)
|
m.fail_json(msg=pkg._failure_string)
|
||||||
|
@ -659,7 +674,7 @@ def main():
|
||||||
cache_valid_time = dict(type='int'),
|
cache_valid_time = dict(type='int'),
|
||||||
purge = dict(default=False, type='bool'),
|
purge = dict(default=False, type='bool'),
|
||||||
package = dict(default=None, aliases=['pkg', 'name'], type='list'),
|
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']),
|
default_release = dict(default=None, aliases=['default-release']),
|
||||||
install_recommends = dict(default=None, aliases=['install-recommends'], type='bool'),
|
install_recommends = dict(default=None, aliases=['install-recommends'], type='bool'),
|
||||||
force = dict(default='no', type='bool'),
|
force = dict(default='no', type='bool'),
|
||||||
|
|
Loading…
Reference in a new issue