def METHOD_NAME():
    module_args = {
        'path': {'type': 'str', 'required': True},
        'keep': {'type': 'int', 'default': 2},
        'shared_dir_for_staticfiles': {'type': 'str'},
        'exclude': {'type': 'list', 'default': [], 'elements': 'str'},
    }
    module = AnsibleModule(
        argument_spec=module_args,
        supports_check_mode=True,
    )
    params = module.params
    releases_path = Path(params["path"])
    _shared_dir = params["shared_dir_for_staticfiles"]
    shared_dir = Path(_shared_dir) if _shared_dir else None
    keep = params["keep"]
    current_release = (releases_path / "current").resolve()
    exclude = set(params["exclude"]) | {"current"}
    if current_release.exists() and current_release.name not in exclude:
        exclude.add(current_release.name)
        keep -= 1
    before = {p.name for p in releases_path.iterdir() if p.is_dir() and not p.name.startswith('.')}
    before_list = sorted(before)
    diff = {'before': {'releases': before_list}, 'after': {'releases': before_list}}
    result = {'changed': False, 'diff': diff}
    exclude.update(name for name in before if should_keep(releases_path / name))
    def prioritize(name):
        build_complete = releases_path / name / BUILD_COMPLETE
        return (int(build_complete.exists()), name)
    to_remove = sorted(before - exclude, key=prioritize, reverse=True)[keep:]
    assert current_release.name not in to_remove, (to_remove, current_release)
    if to_remove:
        result["changed"] = True
        diff["after"]['releases'] = after = sorted(before - set(to_remove))
        assert len(after) >= params["keep"], (diff, params["keep"])
        if not module.check_mode:
            keep_shares = {get_code_version(releases_path / k) for k in before - set(to_remove)}
            keep_shares.add(None) # None prevents rm when get_code_version(...) returns None
            for name in to_remove:
                if shared_dir:
                    delete_shared(releases_path / name, shared_dir, keep_shares, module)
                module.run_command(["rm", "-rf", releases_path / name])
    module.exit_json(**result)