def remove(name=None,
           pkgs=None,
           jail=None,
           chroot=None,
           all_installed=False,
           force=False,
           glob=False,
           dryrun=False,
           recurse=False,
           regex=False,
           pcre=False,
           **kwargs):
    try:
        pkg_params = __salt__['pkg_resource.parse_targets'](name, pkgs)[0]
    except MinionError as exc:
        raise CommandExecutionError(exc)

    targets = []
    old = list_pkgs(jail=jail, chroot=chroot, with_origin=True)
    for pkg in pkg_params.items():
        # FreeBSD pkg supports `openjdk` and `java/openjdk7` package names
        if pkg[0].find("/") > 0:
            origin = pkg[0]
            pkg = [k for k, v in old.iteritems() if v['origin'] == origin][0]

        if pkg[0] in old:
            targets.append(pkg[0])

    if not targets:
        return {}

    opts = ''
    if salt.utils.is_true(all_installed):
        opts += 'a'
    if salt.utils.is_true(force):
        opts += 'f'
    if salt.utils.is_true(glob):
        opts += 'g'
    if salt.utils.is_true(dryrun):
        opts += 'n'
    if not salt.utils.is_true(dryrun):
        opts += 'y'
    if salt.utils.is_true(recurse):
        opts += 'R'
    if salt.utils.is_true(regex):
        opts += 'x'
    if salt.utils.is_true(pcre):
        opts += 'X'

    cmd = _pkg(jail, chroot)
    cmd.append('delete')
    if opts:
        cmd.append('-' + opts)
    cmd.extend(targets)

    out = __salt__['cmd.run_all'](
        cmd,
        output_loglevel='trace',
        python_shell=False
    )

    if out['retcode'] != 0 and out['stderr']:
        errors = [out['stderr']]
    else:
        errors = []

    __context__.pop(_contextkey(jail, chroot), None)
    __context__.pop(_contextkey(jail, chroot, prefix='pkg.origin'), None)
    new = list_pkgs(jail=jail, chroot=chroot, with_origin=True)
    ret = salt.utils.compare_dicts(old, new)

    if errors:
        raise CommandExecutionError(
            'Problem encountered removing package(s)',
            info={'errors': errors, 'changes': ret}
        )

    return ret

# Support pkg.delete to remove packages, since this is the CLI usage
Remove a package from the database and system
dataset/ETHPy150Open saltstack/salt/salt/modules/pkgng.py/remove