|
|
@ -69,15 +69,23 @@ def package_status(m, pkgname, version, cache):
|
|
|
|
return pkg.isInstalled, pkg.isUpgradable
|
|
|
|
return pkg.isInstalled, pkg.isUpgradable
|
|
|
|
|
|
|
|
|
|
|
|
def install(m, pkgspec, cache, upgrade=False, default_release=None, install_recommends=True, force=False):
|
|
|
|
def install(m, pkgspec, cache, upgrade=False, default_release=None, install_recommends=True, force=False):
|
|
|
|
name, version = package_split(pkgspec)
|
|
|
|
packages = list()
|
|
|
|
installed, upgradable = package_status(m, name, version, cache)
|
|
|
|
for package in pkgspec:
|
|
|
|
if not installed or (upgrade and upgradable):
|
|
|
|
name, version = package_split(package)
|
|
|
|
|
|
|
|
installed, upgradable = package_status(m, name, version, cache)
|
|
|
|
|
|
|
|
if not installed or (upgrade and upgradable):
|
|
|
|
|
|
|
|
packages.append(package)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(packages) >0:
|
|
|
|
if force:
|
|
|
|
if force:
|
|
|
|
force_yes = '--force-yes'
|
|
|
|
force_yes = '--force-yes'
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
force_yes = ''
|
|
|
|
force_yes = ''
|
|
|
|
|
|
|
|
|
|
|
|
cmd = "%s --option Dpkg::Options::=--force-confold -q -y %s install '%s'" % (APT, force_yes, pkgspec)
|
|
|
|
cmd = "%s --option Dpkg::Options::=--force-confold -q -y %s install " % (APT, force_yes)
|
|
|
|
|
|
|
|
for package in packages:
|
|
|
|
|
|
|
|
cmd += " '%s'" % package
|
|
|
|
|
|
|
|
|
|
|
|
if default_release:
|
|
|
|
if default_release:
|
|
|
|
cmd += " -t '%s'" % (default_release,)
|
|
|
|
cmd += " -t '%s'" % (default_release,)
|
|
|
|
if not install_recommends:
|
|
|
|
if not install_recommends:
|
|
|
@ -92,16 +100,23 @@ def install(m, pkgspec, cache, upgrade=False, default_release=None, install_reco
|
|
|
|
m.exit_json(changed=False)
|
|
|
|
m.exit_json(changed=False)
|
|
|
|
|
|
|
|
|
|
|
|
def remove(m, pkgspec, cache, purge=False):
|
|
|
|
def remove(m, pkgspec, cache, purge=False):
|
|
|
|
name, version = package_split(pkgspec)
|
|
|
|
packages = list()
|
|
|
|
installed, upgradable = package_status(m, name, version, cache)
|
|
|
|
for package in pkgspec:
|
|
|
|
if not installed:
|
|
|
|
name, version = package_split(package)
|
|
|
|
|
|
|
|
installed, upgradable = package_status(m, name, version, cache)
|
|
|
|
|
|
|
|
if installed:
|
|
|
|
|
|
|
|
packages.append(name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(packages) == 0:
|
|
|
|
m.exit_json(changed=False)
|
|
|
|
m.exit_json(changed=False)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
purge = '--purge' if purge else ''
|
|
|
|
purge = '--purge' if purge else ''
|
|
|
|
cmd = "%s -q -y %s remove '%s'" % (APT, purge, name)
|
|
|
|
cmd = "%s -q -y %s remove" % (APT, purge)
|
|
|
|
|
|
|
|
for package in packages:
|
|
|
|
|
|
|
|
cmd += " '%s'" % package
|
|
|
|
rc, out, err = run_apt(cmd)
|
|
|
|
rc, out, err = run_apt(cmd)
|
|
|
|
if rc:
|
|
|
|
if rc:
|
|
|
|
m.fail_json(msg="'apt-get remove %s' failed: %s" % (name, err))
|
|
|
|
m.fail_json(msg="'apt-get remove %s' failed: %s" % (packages, err))
|
|
|
|
m.exit_json(changed=True)
|
|
|
|
m.exit_json(changed=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -145,23 +160,26 @@ def main():
|
|
|
|
module.exit_json(changed=False)
|
|
|
|
module.exit_json(changed=False)
|
|
|
|
|
|
|
|
|
|
|
|
force_yes = module.boolean(p['force'])
|
|
|
|
force_yes = module.boolean(p['force'])
|
|
|
|
|
|
|
|
|
|
|
|
if p['package'].count('=') > 1:
|
|
|
|
packages = p['package'].split(',')
|
|
|
|
module.fail_json(msg='invalid package spec')
|
|
|
|
for package in packages:
|
|
|
|
|
|
|
|
if package.count('=') > 1:
|
|
|
|
|
|
|
|
module.fail_json(msg="invalid package spec: %s" % packages)
|
|
|
|
|
|
|
|
|
|
|
|
if p['state'] == 'latest':
|
|
|
|
if p['state'] == 'latest':
|
|
|
|
if '=' in p['package']:
|
|
|
|
for package in packages:
|
|
|
|
module.fail_json(msg='version number inconsistent with state=latest')
|
|
|
|
if '=' in package:
|
|
|
|
install(module, p['package'], cache, upgrade=True,
|
|
|
|
module.fail_json(msg='version number inconsistent with state=latest')
|
|
|
|
default_release=p['default_release'],
|
|
|
|
install(module, packages, cache, upgrade=True,
|
|
|
|
install_recommends=install_recommends,
|
|
|
|
default_release=p['default_release'],
|
|
|
|
force=force_yes)
|
|
|
|
install_recommends=install_recommends,
|
|
|
|
|
|
|
|
force=force_yes)
|
|
|
|
|
|
|
|
|
|
|
|
elif p['state'] == 'installed':
|
|
|
|
elif p['state'] == 'installed':
|
|
|
|
install(module, p['package'], cache, default_release=p['default_release'],
|
|
|
|
install(module, packages, cache, default_release=p['default_release'],
|
|
|
|
install_recommends=install_recommends,force=force_yes)
|
|
|
|
install_recommends=install_recommends,force=force_yes)
|
|
|
|
elif p['state'] == 'removed':
|
|
|
|
elif p['state'] == 'removed':
|
|
|
|
remove(module, p['package'], cache, purge = module.boolean(p['purge']))
|
|
|
|
remove(module, packages, cache, purge = module.boolean(p['purge']))
|
|
|
|
|
|
|
|
|
|
|
|
# this is magic, see lib/ansible/module_common.py
|
|
|
|
# this is magic, see lib/ansible/module_common.py
|
|
|
|
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
|
|
|
|
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
|
|
|
|