homebrew_service: remove redundant code (#11839)

* homebrew_service: remove redundant code

* homebrew_services: add changelog fragment for #11839

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Alexei Znamensky
2026-04-19 08:45:21 +12:00
committed by GitHub
parent edf8f24959
commit afe9de7562
2 changed files with 7 additions and 8 deletions

View File

@@ -0,0 +1,4 @@
minor_changes:
- homebrew_services - remove various redundancies including dead state validation, unused return
values, and unnecessary locale environment variables
(https://github.com/ansible-collections/community.general/pull/11839).

View File

@@ -139,9 +139,6 @@ def validate_and_load_arguments(module: AnsibleModule) -> HomebrewServiceArgs:
module.fail_json(msg=f"Invalid package name: {package}")
state: t.Literal["present", "absent", "restarted"] = module.params["state"]
if state not in ["present", "absent", "restarted"]:
module.fail_json(msg=f"Invalid state: {state}")
brew_path = parse_brew_path(module)
return HomebrewServiceArgs(name=package, state=state, brew_path=brew_path)
@@ -158,7 +155,7 @@ def start_service(args: HomebrewServiceArgs, module: AnsibleModule) -> None:
_exit_with_state(args, module, changed=True, message="Service would be started")
start_cmd = [args.brew_path, "services", "start", args.name]
rc, stdout, stderr = module.run_command(start_cmd, check_rc=True)
module.run_command(start_cmd, check_rc=True)
_exit_with_state(args, module, changed=True)
@@ -174,7 +171,7 @@ def stop_service(args: HomebrewServiceArgs, module: AnsibleModule) -> None:
_exit_with_state(args, module, changed=True, message="Service would be stopped")
stop_cmd = [args.brew_path, "services", "stop", args.name]
rc, stdout, stderr = module.run_command(stop_cmd, check_rc=True)
module.run_command(stop_cmd, check_rc=True)
_exit_with_state(args, module, changed=True)
@@ -185,7 +182,7 @@ def restart_service(args: HomebrewServiceArgs, module: AnsibleModule) -> None:
_exit_with_state(args, module, changed=True, message="Service would be restarted")
restart_cmd = [args.brew_path, "services", "restart", args.name]
rc, stdout, stderr = module.run_command(restart_cmd, check_rc=True)
module.run_command(restart_cmd, check_rc=True)
_exit_with_state(args, module, changed=True)
@@ -210,8 +207,6 @@ def main() -> None:
supports_check_mode=True,
)
module.run_command_environ_update = dict(LANG="C", LC_ALL="C", LC_MESSAGES="C", LC_CTYPE="C")
# Pre-validate arguments.
service_args = validate_and_load_arguments(module)