Merge pull request #575 from jeremysmitherman/apt-force
Added cmd modifications to use a force-yes option for apt module
This commit is contained in:
commit
4a8a60b656
1 changed files with 20 additions and 5 deletions
25
apt
25
apt
|
@ -86,11 +86,16 @@ 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, install_recommends=True):
|
def install(pkgspec, cache, upgrade=False, default_release=None, install_recommends=True, force=False):
|
||||||
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)
|
if force:
|
||||||
|
force_yes = '--force-yes'
|
||||||
|
else:
|
||||||
|
force_yes = ''
|
||||||
|
|
||||||
|
cmd = "%s --option Dpkg::Options::=--force-confold -q -y %s install '%s'" % (APT, force_yes, pkgspec)
|
||||||
if default_release:
|
if default_release:
|
||||||
cmd += " -t '%s'" % (default_release,)
|
cmd += " -t '%s'" % (default_release,)
|
||||||
if not install_recommends:
|
if not install_recommends:
|
||||||
|
@ -142,6 +147,7 @@ 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')
|
install_recommends = params.get('install-recommends', 'yes')
|
||||||
|
force = params.get('force', 'no')
|
||||||
|
|
||||||
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 +158,9 @@ if update_cache not in ['yes', 'no']:
|
||||||
if purge not in ['yes', 'no']:
|
if purge not in ['yes', 'no']:
|
||||||
fail_json(msg='invalid value for purge (requires yes or no -- default is no)')
|
fail_json(msg='invalid value for purge (requires yes or no -- default is no)')
|
||||||
|
|
||||||
|
if force not in ['yes', 'no']:
|
||||||
|
fail_json(msg='invalid option for force (requires yes or no -- default is 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')
|
||||||
|
|
||||||
|
@ -171,18 +180,24 @@ if update_cache == 'yes':
|
||||||
if package == None:
|
if package == None:
|
||||||
exit_json(changed=False)
|
exit_json(changed=False)
|
||||||
|
|
||||||
|
if force == 'yes':
|
||||||
|
force_yes = True
|
||||||
|
else:
|
||||||
|
force_yes = False
|
||||||
|
|
||||||
if package.count('=') > 1:
|
if package.count('=') > 1:
|
||||||
fail_json(msg='invalid package spec')
|
fail_json(msg='invalid package spec')
|
||||||
|
|
||||||
if state == 'latest':
|
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)
|
install_recommends=install_recommends,
|
||||||
|
force=force_yes)
|
||||||
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)
|
install_recommends=install_recommends,force=force_yes)
|
||||||
elif state == 'removed':
|
elif state == 'removed':
|
||||||
changed = remove(package, cache, purge == 'yes')
|
changed = remove(package, cache, purge == 'yes')
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue