Hi everyone,
I’m currently working on a module to manage system services with the homebrew services
command. Basically it allows to start, stop, enable and restart services of packages that have been installed using the Homebrew package manager.
The underlying tool doesn’t support all possible states of the other service-type Ansible modules, so I need to develop a simplified module interface for the homebrew_service
module. I’m looking for guidance from core devs whether the module would be mergeable with the interface I’m planning.
Here’s a draft of my current module interface:
`
DOCUMENTATION = ‘’’
module: homebrew_service
short_description: Manage services of Homebrew formulae
description:
- Controls services of Homebrew formulae using the C(brew services) command.
version_added: “2.10”
author: - Lukas Bestle (@lukasbestle)
options:
name:
description: - Name of the Homebrew formula that provides the service.
type: str
required: true
state:
description: - C(started)/C(stopped) are idempotent actions that will not run
commands unless necessary. - C(restarted) will always bounce the service.
type: str
choices: [ restarted, started, stopped ]
required: true
enabled:
description: - Whether the service should start on login/boot.
- B(Note) that switching a running service between being enabled and disabled
requires restarting the service. The restart will be performed automatically. - B(Note) that you cannot set I(state=stopped) together with I(enabled=yes) as
stopping a Homebrew service automatically disables it. - “The default value is: for I(state=started): C(yes); for I(state=stopped): C(no);
for I(state=restarted): keep the current value.”
type: bool
requirements: - macOS (Homebrew on Linux is not supported).
- Homebrew must already be installed on the target system.
notes: - This module supports C(check_mode).
‘’’
EXAMPLES = ‘’’
-
name: Start service httpd on each login and start it now, if not started
homebrew_service:
name: httpd
state: started -
name: Start service httpd in this session, if not started
homebrew_service:
name: httpd
state: started
enabled: no -
name: Start service dnsmasq as a system service on each boot and start it now, if not started
homebrew_service:
name: dnsmasq
state: started
become: yes -
name: Stop service httpd, if started
homebrew_service:
name: httpd
state: stopped -
name: Stop system service dnsmasq, if started
homebrew_service:
name: dnsmasq
state: stopped
become: yes -
name: Restart service httpd, in all cases
homebrew_service:
name: httpd
state: restarted -
name: Ensure that the service httpd is enabled and restart it, in all cases
homebrew_service:
name: httpd
state: restarted
enabled: yes
‘’’
`
Would this interface be alright for this module to get merged? Or is it a problem that the interface is slightly inconsistent with the other service-type modules? What I want to avoid is that I develop the module and it won’t get merged because the features differ from the other modules (which has happened with the launchd module before).
I look forward to your opinions and your feedback.
Cheers,
Lukas