1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-21 03:09:04 +00:00

[PR #11839/afe9de75 backport][stable-12] homebrew_service: remove redundant code (#11876)

homebrew_service: remove redundant code (#11839)

* homebrew_service: remove redundant code

* homebrew_services: add changelog fragment for #11839



---------


(cherry picked from commit afe9de7562)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
patchback[bot] 2026-04-18 22:55:25 +02:00 committed by GitHub
parent ae05131a54
commit 3867300eca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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)