community.general icon indicating copy to clipboard operation
community.general copied to clipboard

homebrew: Add support for services functions

Open kitizz opened this issue 10 months ago • 9 comments

Summary

I'd like to add support for things like:

brew services start foo
brew services stop foo
brew services restart foo
brew services kill foo

More than happy to implement it myself. But I am looking for some advice from the maintainers.

Issue Type

Feature Idea

Component Name

homebrew

Additional Information

Specifically, should I follow the current pattern of the update function and add a service parameter to the current homebrew module? Or should I add a new homebrew_services module?

I personally feel like a new module makes the most sense. Here are my current thoughts on the two choices:

Add a service parameter

- name: Install foo package
  homebrew:
    name: foo
    state: present

- name: Start the foo service
  homebrew:
    service: foo
    service_state: present  # brew services start foo

- name: Restart the foo service
  homebrew:
    service: foo
    service_state: restarted  # brew services restart foo
    

- name: Remove the foo service
  homebrew:
    service: foo
    service_state: absent  # brew services stop foo
  • 👍 Somewhat consistent with existing patterns (though homebrew_cask module throws me a bit)
  • 👍 Smaller PR, not adding a whole new module
  • 👎 Kind of weird to allow name: and service: to both be defined. And while the order of operations is obvious (install before service), that all needs to be defined and maintained.

Add a homebrew_services module

- name: Install foo package
  homebrew:
    name: foo
    state: present

- name: Start the foo service
  homebrew_service:
    name: foo
    state: present  # brew services start foo

- name: Restart the foo service
  homebrew_service:
    name: foo
    state: restarted  # brew services restart foo

- name: Remove the foo service
  homebrew_service:
    name: foo
    service_state: absent  # brew services stop foo
  • 👍 Allows for parameter names that remain consistent with other collections and modules in my (very light) research
  • 👍 Organization would also be consistent with other collections (e.g. docker)

Code of Conduct

  • [X] I agree to follow the Ansible Code of Conduct

kitizz avatar Apr 27 '24 09:04 kitizz

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

ansibullbot avatar Apr 27 '24 09:04 ansibullbot

cc @Akasurde @danieljaouen @indrajitr @kyleabenson @martinm82 click here for bot help

ansibullbot avatar Apr 27 '24 09:04 ansibullbot

I'm not a homebrew user, but having a separate module is usually a better idea. Otherwise you eventually end up with 'monsters' such as docker_image, which has way too many options for way too many different operations. That makes the module's code pretty complex, and the module's documentation more confusing (you see a looong list of options and have to figure out which ones are actually relevant for your use-case).

felixfontein avatar Apr 28 '24 12:04 felixfontein

!component =plugins/modules/homebrew

felixfontein avatar Apr 28 '24 12:04 felixfontein

Files identified in the description:

  • plugins/modules/homebrew

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

ansibullbot avatar Apr 28 '24 12:04 ansibullbot

!component =plugins/modules/homebrew.py !component +plugins/modules/homebrew_cask.py !component +plugins/modules/homebrew_tap.py

felixfontein avatar Apr 28 '24 12:04 felixfontein

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

ansibullbot avatar Apr 28 '24 12:04 ansibullbot

cc @andrew-d @enriclluelles click here for bot help

ansibullbot avatar Apr 28 '24 12:04 ansibullbot

Yup, sounds good to me. Hopefully be back within the week with a PR

kitizz avatar Apr 29 '24 09:04 kitizz