mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Freebsd pkgng autoremove support (#2324)
* Whitespace cleanup * Add autoremove capability to pkgng * Add "default" and "choices" documentnation items for autoremove
This commit is contained in:
parent
e6766078ea
commit
472bf733e0
1 changed files with 37 additions and 7 deletions
|
@ -75,6 +75,13 @@ options:
|
||||||
- pkg will chroot in the specified environment
|
- pkg will chroot in the specified environment
|
||||||
- can not be used together with 'rootdir' option
|
- can not be used together with 'rootdir' option
|
||||||
required: false
|
required: false
|
||||||
|
autoremove:
|
||||||
|
version_added: "2.2"
|
||||||
|
description:
|
||||||
|
- remove automatically installed packages which are no longer needed
|
||||||
|
required: false
|
||||||
|
choices: [ "yes", "no" ]
|
||||||
|
default: no
|
||||||
author: "bleader (@bleader)"
|
author: "bleader (@bleader)"
|
||||||
notes:
|
notes:
|
||||||
- When using pkgsite, be careful that already in cache packages won't be downloaded again.
|
- When using pkgsite, be careful that already in cache packages won't be downloaded again.
|
||||||
|
@ -271,6 +278,23 @@ def annotate_packages(module, pkgng_path, packages, annotation, dir_arg):
|
||||||
return (True, "added %s annotations." % annotate_c)
|
return (True, "added %s annotations." % annotate_c)
|
||||||
return (False, "changed no annotations")
|
return (False, "changed no annotations")
|
||||||
|
|
||||||
|
def autoremove_packages(module, pkgng_path, dir_arg):
|
||||||
|
rc, out, err = module.run_command("%s %s autoremove -n" % (pkgng_path, dir_arg))
|
||||||
|
|
||||||
|
autoremove_c = 0
|
||||||
|
|
||||||
|
match = re.search('^Deinstallation has been requested for the following ([0-9]+) packages', out, re.MULTILINE)
|
||||||
|
if match:
|
||||||
|
autoremove_c = int(match.group(1))
|
||||||
|
|
||||||
|
if autoremove_c == 0:
|
||||||
|
return False, "no package(s) to autoremove"
|
||||||
|
|
||||||
|
if not module.check_mode:
|
||||||
|
rc, out, err = module.run_command("%s %s autoremove -y" % (pkgng_path, dir_arg))
|
||||||
|
|
||||||
|
return True, "autoremoved %d package(s)" % (autoremove_c)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
|
@ -280,7 +304,8 @@ def main():
|
||||||
annotation = dict(default="", required=False),
|
annotation = dict(default="", required=False),
|
||||||
pkgsite = dict(default="", required=False),
|
pkgsite = dict(default="", required=False),
|
||||||
rootdir = dict(default="", required=False, type='path'),
|
rootdir = dict(default="", required=False, type='path'),
|
||||||
chroot = dict(default="", required=False, type='path')),
|
chroot = dict(default="", required=False, type='path'),
|
||||||
|
autoremove = dict(default=False, type='bool')),
|
||||||
supports_check_mode = True,
|
supports_check_mode = True,
|
||||||
mutually_exclusive =[["rootdir", "chroot"]])
|
mutually_exclusive =[["rootdir", "chroot"]])
|
||||||
|
|
||||||
|
@ -302,7 +327,7 @@ def main():
|
||||||
dir_arg = "--rootdir %s" % (p["rootdir"])
|
dir_arg = "--rootdir %s" % (p["rootdir"])
|
||||||
|
|
||||||
if p["chroot"] != "":
|
if p["chroot"] != "":
|
||||||
dir_arg = '--chroot %s' % (p["chroot"])
|
dir_arg = '--chroot %s' % (p["chroot"])
|
||||||
|
|
||||||
if p["state"] == "present":
|
if p["state"] == "present":
|
||||||
_changed, _msg = install_packages(module, pkgng_path, pkgs, p["cached"], p["pkgsite"], dir_arg)
|
_changed, _msg = install_packages(module, pkgng_path, pkgs, p["cached"], p["pkgsite"], dir_arg)
|
||||||
|
@ -314,6 +339,11 @@ def main():
|
||||||
changed = changed or _changed
|
changed = changed or _changed
|
||||||
msgs.append(_msg)
|
msgs.append(_msg)
|
||||||
|
|
||||||
|
if p["autoremove"]:
|
||||||
|
_changed, _msg = autoremove_packages(module, pkgng_path, dir_arg)
|
||||||
|
changed = changed or _changed
|
||||||
|
msgs.append(_msg)
|
||||||
|
|
||||||
if p["annotation"]:
|
if p["annotation"]:
|
||||||
_changed, _msg = annotate_packages(module, pkgng_path, pkgs, p["annotation"], dir_arg)
|
_changed, _msg = annotate_packages(module, pkgng_path, pkgs, p["annotation"], dir_arg)
|
||||||
changed = changed or _changed
|
changed = changed or _changed
|
||||||
|
|
Loading…
Reference in a new issue