|
|
@ -150,25 +150,30 @@ def package_status(m, pkgname, version, cache, state):
|
|
|
|
if state == 'install':
|
|
|
|
if state == 'install':
|
|
|
|
m.fail_json(msg="No package matching '%s' is available" % pkgname)
|
|
|
|
m.fail_json(msg="No package matching '%s' is available" % pkgname)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return False, False
|
|
|
|
return False, False, False
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
has_files = len(pkg.installed_files) > 0
|
|
|
|
|
|
|
|
except AttributeError:
|
|
|
|
|
|
|
|
has_files = False # older python-apt cannot be used to determine non-purged
|
|
|
|
|
|
|
|
|
|
|
|
if version:
|
|
|
|
if version:
|
|
|
|
try :
|
|
|
|
try :
|
|
|
|
return pkg.is_installed and fnmatch.fnmatch(pkg.installed.version, version), False
|
|
|
|
return pkg.is_installed and fnmatch.fnmatch(pkg.installed.version, version), False, has_files
|
|
|
|
except AttributeError:
|
|
|
|
except AttributeError:
|
|
|
|
#assume older version of python-apt is installed
|
|
|
|
#assume older version of python-apt is installed
|
|
|
|
return pkg.isInstalled and fnmatch.fnmatch(pkg.installedVersion, version), False
|
|
|
|
return pkg.isInstalled and fnmatch.fnmatch(pkg.installedVersion, version), False, has_files
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
try :
|
|
|
|
try :
|
|
|
|
return pkg.is_installed, pkg.is_upgradable
|
|
|
|
return pkg.is_installed, pkg.is_upgradable, has_files
|
|
|
|
except AttributeError:
|
|
|
|
except AttributeError:
|
|
|
|
#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, has_files
|
|
|
|
|
|
|
|
|
|
|
|
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):
|
|
|
|
packages = ""
|
|
|
|
packages = ""
|
|
|
|
for package in pkgspec:
|
|
|
|
for package in pkgspec:
|
|
|
|
name, version = package_split(package)
|
|
|
|
name, version = package_split(package)
|
|
|
|
installed, upgradable = package_status(m, name, version, cache, state='install')
|
|
|
|
installed, upgradable, has_files = package_status(m, name, version, cache, state='install')
|
|
|
|
if not installed or (upgrade and upgradable):
|
|
|
|
if not installed or (upgrade and upgradable):
|
|
|
|
packages += "'%s' " % package
|
|
|
|
packages += "'%s' " % package
|
|
|
|
|
|
|
|
|
|
|
@ -202,16 +207,17 @@ def remove(m, pkgspec, cache, purge=False):
|
|
|
|
packages = ""
|
|
|
|
packages = ""
|
|
|
|
for package in pkgspec:
|
|
|
|
for package in pkgspec:
|
|
|
|
name, version = package_split(package)
|
|
|
|
name, version = package_split(package)
|
|
|
|
installed, upgradable = package_status(m, name, version, cache, state='remove')
|
|
|
|
installed, upgradable, has_files = package_status(m, name, version, cache, state='remove')
|
|
|
|
if installed:
|
|
|
|
if installed or (has_files and purge):
|
|
|
|
packages += "'%s' " % package
|
|
|
|
packages += "'%s' " % package
|
|
|
|
|
|
|
|
|
|
|
|
if len(packages) == 0:
|
|
|
|
if len(packages) == 0:
|
|
|
|
m.exit_json(changed=False)
|
|
|
|
m.exit_json(changed=False)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
purge = ''
|
|
|
|
|
|
|
|
if purge:
|
|
|
|
if purge:
|
|
|
|
purge = '--purge'
|
|
|
|
purge = '--purge'
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
purge = ''
|
|
|
|
cmd = "%s -q -y %s remove %s" % (APT_GET_CMD, purge,packages)
|
|
|
|
cmd = "%s -q -y %s remove %s" % (APT_GET_CMD, purge,packages)
|
|
|
|
|
|
|
|
|
|
|
|
if m.check_mode:
|
|
|
|
if m.check_mode:
|
|
|
|