homebrew: Add support for services functions (#8329)

* Homebrew: Add support for services functions

Fixes #8286.
Add a homebrew.services module for starting and stopping services
that are attached to homebrew packages.

* Address python version compatibility

* Addressing reviewer comments

* Addressing sanity logs

* Address str format issues

* Fixing Python 2.7 syntax issues

* Test alias, BOTMETA, grammar

* Attempt to fix brew in tests

* Address comments by russoz

* Fixing more dumb typos

* Actually uninstall black

* Update version_added in plugins/modules/homebrew_services.py

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Kit Ham 2024-08-02 03:11:23 +12:00 committed by GitHub
parent 229ed6dad9
commit 2963004991
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 394 additions and 0 deletions

View file

@ -113,3 +113,30 @@ class HomebrewValidate(object):
return isinstance(
package, string_types
) and not cls.INVALID_PACKAGE_REGEX.search(package)
def parse_brew_path(module):
# type: (...) -> str
"""Attempt to find the Homebrew executable path.
Requires:
- module has a `path` parameter
- path is a valid path string for the target OS. Otherwise, module.fail_json()
is called with msg="Invalid_path: <path>".
"""
path = module.params["path"]
if not HomebrewValidate.valid_path(path):
module.fail_json(msg="Invalid path: {0}".format(path))
if isinstance(path, string_types):
paths = path.split(":")
elif isinstance(path, list):
paths = path
else:
module.fail_json(msg="Invalid path: {0}".format(path))
brew_path = module.get_bin_path("brew", required=True, opt_dirs=paths)
if not HomebrewValidate.valid_brew_path(brew_path):
module.fail_json(msg="Invalid brew path: {0}".format(brew_path))
return brew_path