mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #546 from pas256/devel
apt module to support --no-install-recommends
This commit is contained in:
commit
749472559b
1 changed files with 18 additions and 9 deletions
27
library/apt
27
library/apt
|
@ -86,13 +86,15 @@ def package_status(pkgname, version, cache):
|
||||||
#assume older version of python-apt is installed
|
#assume older version of python-apt is installed
|
||||||
return pkg.isInstalled, pkg.isUpgradable
|
return pkg.isInstalled, pkg.isUpgradable
|
||||||
|
|
||||||
def install(pkgspec, cache, upgrade=False, default_release=None):
|
def install(pkgspec, cache, upgrade=False, default_release=None, install_recommends=True):
|
||||||
name, version = package_split(pkgspec)
|
name, version = package_split(pkgspec)
|
||||||
installed, upgradable = package_status(name, version, cache)
|
installed, upgradable = package_status(name, version, cache)
|
||||||
if not installed or (upgrade and upgradable):
|
if not installed or (upgrade and upgradable):
|
||||||
cmd = "%s --option Dpkg::Options::=--force-confold -q -y install '%s'" % (APT, pkgspec)
|
cmd = "%s --option Dpkg::Options::=--force-confold -q -y install '%s'" % (APT, pkgspec)
|
||||||
if default_release:
|
if default_release:
|
||||||
cmd += " -t '%s'" % (default_release,)
|
cmd += " -t '%s'" % (default_release,)
|
||||||
|
if not install_recommends:
|
||||||
|
cmd += " --no-install-recommends"
|
||||||
rc, out, err = run_apt(cmd)
|
rc, out, err = run_apt(cmd)
|
||||||
if rc:
|
if rc:
|
||||||
fail_json(msg="'apt-get install %s' failed: %s" % (pkgspec, err))
|
fail_json(msg="'apt-get install %s' failed: %s" % (pkgspec, err))
|
||||||
|
@ -117,7 +119,7 @@ def remove(pkgspec, cache, purge=False):
|
||||||
# ===========================================
|
# ===========================================
|
||||||
|
|
||||||
if not os.path.exists(APT_PATH):
|
if not os.path.exists(APT_PATH):
|
||||||
fail_json(msg="Cannot find apt-get")
|
fail_json(msg="Cannot find apt-get")
|
||||||
|
|
||||||
argfile = sys.argv[1]
|
argfile = sys.argv[1]
|
||||||
args = open(argfile, 'r').read()
|
args = open(argfile, 'r').read()
|
||||||
|
@ -134,11 +136,12 @@ for x in items:
|
||||||
(k, v) = x.split("=", 1)
|
(k, v) = x.split("=", 1)
|
||||||
params[k] = v
|
params[k] = v
|
||||||
|
|
||||||
state = params.get('state', 'installed')
|
state = params.get('state', 'installed')
|
||||||
package = params.get('pkg', params.get('package', params.get('name', None)))
|
package = params.get('pkg', params.get('package', params.get('name', None)))
|
||||||
update_cache = params.get('update-cache', 'no')
|
update_cache = params.get('update-cache', 'no')
|
||||||
purge = params.get('purge', 'no')
|
purge = params.get('purge', 'no')
|
||||||
default_release = params.get('default-release', None)
|
default_release = params.get('default-release', None)
|
||||||
|
install_recommends = params.get('install-recommends', 'yes')
|
||||||
|
|
||||||
if state not in ['installed', 'latest', 'removed']:
|
if state not in ['installed', 'latest', 'removed']:
|
||||||
fail_json(msg='invalid state')
|
fail_json(msg='invalid state')
|
||||||
|
@ -152,6 +155,10 @@ if purge not in ['yes', 'no']:
|
||||||
if package is None and update_cache != 'yes':
|
if package is None and update_cache != 'yes':
|
||||||
fail_json(msg='pkg=name and/or update-cache=yes is required')
|
fail_json(msg='pkg=name and/or update-cache=yes is required')
|
||||||
|
|
||||||
|
if install_recommends not in ['yes', 'no']:
|
||||||
|
fail_json(msg='invalid value for install-recommends (requires yes or no -- default is yes)')
|
||||||
|
install_recommends = (install_recommends == 'yes')
|
||||||
|
|
||||||
cache = apt.Cache()
|
cache = apt.Cache()
|
||||||
if default_release:
|
if default_release:
|
||||||
apt_pkg.config['APT::Default-Release'] = default_release
|
apt_pkg.config['APT::Default-Release'] = default_release
|
||||||
|
@ -171,9 +178,11 @@ if state == 'latest':
|
||||||
if '=' in package:
|
if '=' in package:
|
||||||
fail_json(msg='version number inconsistent with state=latest')
|
fail_json(msg='version number inconsistent with state=latest')
|
||||||
changed = install(package, cache, upgrade=True,
|
changed = install(package, cache, upgrade=True,
|
||||||
default_release=default_release)
|
default_release=default_release,
|
||||||
|
install_recommends=install_recommends)
|
||||||
elif state == 'installed':
|
elif state == 'installed':
|
||||||
changed = install(package, cache, default_release=default_release)
|
changed = install(package, cache, default_release=default_release,
|
||||||
|
install_recommends=install_recommends)
|
||||||
elif state == 'removed':
|
elif state == 'removed':
|
||||||
changed = remove(package, cache, purge == 'yes')
|
changed = remove(package, cache, purge == 'yes')
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue