community.general
community.general copied to clipboard
homebrew: Add support for services functions
SUMMARY
Add a homebrew.services module for starting and stopping services that are attached to homebrew packages.
Fixes #8286.
ISSUE TYPE
- Feature Pull Request
- New Module/Plugin Pull Request
COMPONENT NAME
homebrew, homebrew_services
ADDITIONAL INFORMATION
Can now make sure a homebrew service is running with:
- name: Ensure the colima service is running
community.general.homebrew_services:
name: colima
state: present
The test ansible-test sanity --test pylint
[explain] failed with 1 error:
plugins/module_utils/homebrew.py:138:0: trailing-whitespace: Trailing whitespace
The test botmeta
failed with 2 errors:
.github/BOTMETA.yml:0:0: Author kitizz not mentioned as active or inactive maintainer for plugins/modules/homebrew_services.py (mentioned are: )
.github/BOTMETA.yml:0:0: No (active or inactive) maintainer mentioned for plugins/modules/homebrew_services.py
The test ansible-test sanity --test compile --python 2.7
[explain] failed with 2 errors:
plugins/module_utils/homebrew.py:118:29: SyntaxError: def parse_brew_path(module) -> str:
plugins/modules/homebrew_services.py:114:9: SyntaxError: name: str
The test ansible-test sanity --test import --python 2.7
[explain] failed with 4 errors:
plugins/module_utils/homebrew.py:118:29: traceback: SyntaxError: invalid syntax
plugins/modules/homebrew.py:184:0: traceback: SyntaxError: invalid syntax (at plugins/module_utils/homebrew.py:118:29)
plugins/modules/homebrew_cask.py:161:0: traceback: SyntaxError: invalid syntax (at plugins/module_utils/homebrew.py:118:29)
plugins/modules/homebrew_services.py:114:9: traceback: SyntaxError: invalid syntax
The test ansible-test sanity --test import --python 3.6
[explain] failed with 1 error:
plugins/modules/homebrew_services.py:98:0: traceback: ModuleNotFoundError: No module named 'dataclasses'
The test ansible-test sanity --test pep8
[explain] failed with 4 errors:
plugins/module_utils/homebrew.py:138:1: W293: blank line contains whitespace
plugins/modules/homebrew_services.py:160:1: W293: blank line contains whitespace
plugins/modules/homebrew_services.py:170:1: W293: blank line contains whitespace
plugins/modules/homebrew_services.py:188:1: W293: blank line contains whitespace
The test ansible-test sanity --test pep8
[explain] failed with 4 errors:
plugins/module_utils/homebrew.py:138:1: W293: blank line contains whitespace
plugins/modules/homebrew_services.py:160:1: W293: blank line contains whitespace
plugins/modules/homebrew_services.py:170:1: W293: blank line contains whitespace
plugins/modules/homebrew_services.py:188:1: W293: blank line contains whitespace
The test ansible-test sanity --test compile --python 2.7
[explain] failed with 2 errors:
plugins/module_utils/homebrew.py:118:29: SyntaxError: def parse_brew_path(module) -> str:
plugins/modules/homebrew_services.py:114:9: SyntaxError: name: str
The test ansible-test sanity --test compile --python 3.5
[explain] failed with 1 error:
plugins/modules/homebrew_services.py:114:9: SyntaxError: name: str
The test ansible-test sanity --test import --python 2.7
[explain] failed with 4 errors:
plugins/module_utils/homebrew.py:118:29: traceback: SyntaxError: invalid syntax
plugins/modules/homebrew.py:184:0: traceback: SyntaxError: invalid syntax (at plugins/module_utils/homebrew.py:118:29)
plugins/modules/homebrew_cask.py:161:0: traceback: SyntaxError: invalid syntax (at plugins/module_utils/homebrew.py:118:29)
plugins/modules/homebrew_services.py:114:9: traceback: SyntaxError: invalid syntax
The test ansible-test sanity --test import --python 3.5
[explain] failed with 1 error:
plugins/modules/homebrew_services.py:114:9: traceback: SyntaxError: invalid syntax
The test ansible-test sanity --test import --python 3.6
[explain] failed with 1 error:
plugins/modules/homebrew_services.py:98:0: traceback: ModuleNotFoundError: No module named 'dataclasses'
The test ansible-test sanity --test pep8
[explain] failed with 4 errors:
plugins/module_utils/homebrew.py:138:1: W293: blank line contains whitespace
plugins/modules/homebrew_services.py:160:1: W293: blank line contains whitespace
plugins/modules/homebrew_services.py:170:1: W293: blank line contains whitespace
plugins/modules/homebrew_services.py:188:1: W293: blank line contains whitespace
The test ansible-test sanity --test pep8
[explain] failed with 4 errors:
plugins/module_utils/homebrew.py:138:1: W293: blank line contains whitespace
plugins/modules/homebrew_services.py:160:1: W293: blank line contains whitespace
plugins/modules/homebrew_services.py:170:1: W293: blank line contains whitespace
plugins/modules/homebrew_services.py:188:1: W293: blank line contains whitespace
The test ansible-test sanity --test pylint
[explain] failed with 4 errors:
plugins/modules/homebrew_services.py:99:0: unused-import: Unused Callable imported from typing
plugins/modules/homebrew_services.py:160:0: trailing-whitespace: Trailing whitespace
plugins/modules/homebrew_services.py:170:0: trailing-whitespace: Trailing whitespace
plugins/modules/homebrew_services.py:188:0: trailing-whitespace: Trailing whitespace
The test ansible-test sanity --test validate-modules
[explain] failed with 7 errors:
plugins/modules/homebrew_services.py:0:0: attributes-check-mode: The module does declare support for check mode, but the check_mode attribute's support value is 'None'
plugins/modules/homebrew_services.py:0:0: doc-default-does-not-match-spec: Argument 'state' in argument_spec defines default as (None) but documentation defines default as ('present')
plugins/modules/homebrew_services.py:0:0: doc-required-mismatch: Argument 'name' in argument_spec is required, but is not documented as being required
plugins/modules/homebrew_services.py:0:0: doc-required-mismatch: Argument 'state' in argument_spec is required, but is not documented as being required
plugins/modules/homebrew_services.py:0:0: invalid-documentation: DOCUMENTATION.attributes.check_mode.support: required key not provided @ data['attributes']['check_mode']['support']. Got None
plugins/modules/homebrew_services.py:0:0: invalid-documentation: DOCUMENTATION.attributes.diff_mode.support: required key not provided @ data['attributes']['diff_mode']['support']. Got None
plugins/modules/homebrew_services.py:10:0: import-before-documentation: Import found before documentation variables. All imports must appear below DOCUMENTATION/EXAMPLES/RETURN.
The test ansible-test sanity --test pylint
[explain] failed with 1 error:
plugins/module_utils/homebrew.py:138:0: trailing-whitespace: Trailing whitespace
The test ansible-test sanity --test validate-modules
[explain] failed with 7 errors:
plugins/modules/homebrew_services.py:0:0: attributes-check-mode: The module does declare support for check mode, but the check_mode attribute's support value is 'None'
plugins/modules/homebrew_services.py:0:0: doc-default-does-not-match-spec: Argument 'state' in argument_spec defines default as (None) but documentation defines default as ('present')
plugins/modules/homebrew_services.py:0:0: doc-required-mismatch: Argument 'name' in argument_spec is required, but is not documented as being required
plugins/modules/homebrew_services.py:0:0: doc-required-mismatch: Argument 'state' in argument_spec is required, but is not documented as being required
plugins/modules/homebrew_services.py:0:0: invalid-documentation: DOCUMENTATION.attributes.check_mode.support: required key not provided @ data['attributes']['check_mode']['support']. Got None
plugins/modules/homebrew_services.py:0:0: invalid-documentation: DOCUMENTATION.attributes.diff_mode.support: required key not provided @ data['attributes']['diff_mode']['support']. Got None
plugins/modules/homebrew_services.py:10:0: import-before-documentation: Import found before documentation variables. All imports must appear below DOCUMENTATION/EXAMPLES/RETURN.
The test ansible-test sanity --test pylint
[explain] failed with 4 errors:
plugins/modules/homebrew_services.py:99:0: unused-import: Unused Callable imported from typing
plugins/modules/homebrew_services.py:160:0: trailing-whitespace: Trailing whitespace
plugins/modules/homebrew_services.py:170:0: trailing-whitespace: Trailing whitespace
plugins/modules/homebrew_services.py:188:0: trailing-whitespace: Trailing whitespace
The test ansible-test sanity --test pylint
[explain] failed with 4 errors:
plugins/modules/homebrew_services.py:99:0: unused-import: Unused Callable imported from typing
plugins/modules/homebrew_services.py:160:0: trailing-whitespace: Trailing whitespace
plugins/modules/homebrew_services.py:170:0: trailing-whitespace: Trailing whitespace
plugins/modules/homebrew_services.py:188:0: trailing-whitespace: Trailing whitespace
The test ansible-test sanity --test pylint
[explain] failed with 1 error:
plugins/module_utils/homebrew.py:138:0: trailing-whitespace: Trailing whitespace
The test ansible-test sanity --test validate-modules
[explain] failed with 7 errors:
plugins/modules/homebrew_services.py:0:0: attributes-check-mode: The module does declare support for check mode, but the check_mode attribute's support value is 'None'
plugins/modules/homebrew_services.py:0:0: doc-default-does-not-match-spec: Argument 'state' in argument_spec defines default as (None) but documentation defines default as ('present')
plugins/modules/homebrew_services.py:0:0: doc-required-mismatch: Argument 'name' in argument_spec is required, but is not documented as being required
plugins/modules/homebrew_services.py:0:0: doc-required-mismatch: Argument 'state' in argument_spec is required, but is not documented as being required
plugins/modules/homebrew_services.py:0:0: invalid-documentation: DOCUMENTATION.attributes.check_mode.support: required key not provided @ data['attributes']['check_mode']['support']. Got None
plugins/modules/homebrew_services.py:0:0: invalid-documentation: DOCUMENTATION.attributes.diff_mode.support: required key not provided @ data['attributes']['diff_mode']['support']. Got None
plugins/modules/homebrew_services.py:10:0: import-before-documentation: Import found before documentation variables. All imports must appear below DOCUMENTATION/EXAMPLES/RETURN.
The test ansible-test sanity --test pylint
[explain] failed with 1 error:
plugins/module_utils/homebrew.py:138:0: trailing-whitespace: Trailing whitespace
The test ansible-test sanity --test validate-modules
[explain] failed with 7 errors:
plugins/modules/homebrew_services.py:0:0: attributes-check-mode: The module does declare support for check mode, but the check_mode attribute's support value is 'None'
plugins/modules/homebrew_services.py:0:0: doc-default-does-not-match-spec: Argument 'state' in argument_spec defines default as (None) but documentation defines default as ('present')
plugins/modules/homebrew_services.py:0:0: doc-required-mismatch: Argument 'name' in argument_spec is required, but is not documented as being required
plugins/modules/homebrew_services.py:0:0: doc-required-mismatch: Argument 'state' in argument_spec is required, but is not documented as being required
plugins/modules/homebrew_services.py:0:0: invalid-documentation: DOCUMENTATION.attributes.check_mode.support: required key not provided @ data['attributes']['check_mode']['support']. Got None
plugins/modules/homebrew_services.py:0:0: invalid-documentation: DOCUMENTATION.attributes.diff_mode.support: required key not provided @ data['attributes']['diff_mode']['support']. Got None
plugins/modules/homebrew_services.py:10:0: import-before-documentation: Import found before documentation variables. All imports must appear below DOCUMENTATION/EXAMPLES/RETURN.
The test ansible-test sanity --test pylint
[explain] failed with 4 errors:
plugins/modules/homebrew_services.py:99:0: unused-import: Unused Callable imported from typing
plugins/modules/homebrew_services.py:160:0: trailing-whitespace: Trailing whitespace
plugins/modules/homebrew_services.py:170:0: trailing-whitespace: Trailing whitespace
plugins/modules/homebrew_services.py:188:0: trailing-whitespace: Trailing whitespace
cc @Akasurde @andrew-d @danieljaouen @enriclluelles @indrajitr @kyleabenson @martinm82 click here for bot help
The test botmeta
failed with 2 errors:
.github/BOTMETA.yml:0:0: Author kitizz not mentioned as active or inactive maintainer for plugins/modules/homebrew_services.py (mentioned are: )
.github/BOTMETA.yml:0:0: No (active or inactive) maintainer mentioned for plugins/modules/homebrew_services.py
The test ansible-test sanity --test compile --python 2.7
[explain] failed with 2 errors:
plugins/module_utils/homebrew.py:118:29: SyntaxError: def parse_brew_path(module) -> str:
plugins/modules/homebrew_services.py:150:83: SyntaxError: f"Running: {state.running}, Changed: {state.running}, PID: {state.pid}"
The test ansible-test sanity --test import --python 2.7
[explain] failed with 4 errors:
plugins/module_utils/homebrew.py:118:29: traceback: SyntaxError: invalid syntax
plugins/modules/homebrew.py:184:0: traceback: SyntaxError: invalid syntax (at plugins/module_utils/homebrew.py:118:29)
plugins/modules/homebrew_cask.py:161:0: traceback: SyntaxError: invalid syntax (at plugins/module_utils/homebrew.py:118:29)
plugins/modules/homebrew_services.py:150:83: traceback: SyntaxError: invalid syntax
The test ansible-test sanity --test pep8
[explain] failed with 1 error:
plugins/module_utils/homebrew.py:138:1: W293: blank line contains whitespace
The test ansible-test sanity --test pep8
[explain] failed with 1 error:
plugins/module_utils/homebrew.py:138:1: W293: blank line contains whitespace
The test ansible-test sanity --test compile --python 2.7
[explain] failed with 2 errors:
plugins/module_utils/homebrew.py:118:29: SyntaxError: def parse_brew_path(module) -> str:
plugins/modules/homebrew_services.py:150:83: SyntaxError: f"Running: {state.running}, Changed: {state.running}, PID: {state.pid}"
The test ansible-test sanity --test compile --python 3.5
[explain] failed with 1 error:
plugins/modules/homebrew_services.py:150:83: SyntaxError: f"Running: {state.running}, Changed: {state.running}, PID: {state.pid}"
The test ansible-test sanity --test import --python 2.7
[explain] failed with 4 errors:
plugins/module_utils/homebrew.py:118:29: traceback: SyntaxError: invalid syntax
plugins/modules/homebrew.py:184:0: traceback: SyntaxError: invalid syntax (at plugins/module_utils/homebrew.py:118:29)
plugins/modules/homebrew_cask.py:161:0: traceback: SyntaxError: invalid syntax (at plugins/module_utils/homebrew.py:118:29)
plugins/modules/homebrew_services.py:150:83: traceback: SyntaxError: invalid syntax
The test ansible-test sanity --test import --python 3.5
[explain] failed with 1 error:
plugins/modules/homebrew_services.py:150:83: traceback: SyntaxError: invalid syntax
The test ansible-test sanity --test pep8
[explain] failed with 1 error:
plugins/module_utils/homebrew.py:138:1: W293: blank line contains whitespace
The test ansible-test sanity --test pep8
[explain] failed with 1 error:
plugins/module_utils/homebrew.py:138:1: W293: blank line contains whitespace
The test ansible-test sanity --test validate-modules
[explain] failed with 7 errors:
plugins/modules/homebrew_services.py:0:0: attributes-check-mode: The module does declare support for check mode, but the check_mode attribute's support value is 'None'
plugins/modules/homebrew_services.py:0:0: doc-default-does-not-match-spec: Argument 'state' in argument_spec defines default as (None) but documentation defines default as ('present')
plugins/modules/homebrew_services.py:0:0: doc-required-mismatch: Argument 'name' in argument_spec is required, but is not documented as being required
plugins/modules/homebrew_services.py:0:0: doc-required-mismatch: Argument 'state' in argument_spec is required, but is not documented as being required
plugins/modules/homebrew_services.py:0:0: invalid-documentation: DOCUMENTATION.attributes.check_mode.support: required key not provided @ data['attributes']['check_mode']['support']. Got None
plugins/modules/homebrew_services.py:0:0: invalid-documentation: DOCUMENTATION.attributes.diff_mode.support: required key not provided @ data['attributes']['diff_mode']['support']. Got None
plugins/modules/homebrew_services.py:10:0: import-before-documentation: Import found before documentation variables. All imports must appear below DOCUMENTATION/EXAMPLES/RETURN.
The test ansible-test sanity --test pylint
[explain] failed with 1 error:
plugins/module_utils/homebrew.py:138:0: trailing-whitespace: Trailing whitespace
The test ansible-test sanity --test validate-modules
[explain] failed with 7 errors:
plugins/modules/homebrew_services.py:0:0: attributes-check-mode: The module does declare support for check mode, but the check_mode attribute's support value is 'None'
plugins/modules/homebrew_services.py:0:0: doc-default-does-not-match-spec: Argument 'state' in argument_spec defines default as (None) but documentation defines default as ('present')
plugins/modules/homebrew_services.py:0:0: doc-required-mismatch: Argument 'name' in argument_spec is required, but is not documented as being required
plugins/modules/homebrew_services.py:0:0: doc-required-mismatch: Argument 'state' in argument_spec is required, but is not documented as being required
plugins/modules/homebrew_services.py:0:0: invalid-documentation: DOCUMENTATION.attributes.check_mode.support: required key not provided @ data['attributes']['check_mode']['support']. Got None
plugins/modules/homebrew_services.py:0:0: invalid-documentation: DOCUMENTATION.attributes.diff_mode.support: required key not provided @ data['attributes']['diff_mode']['support']. Got None
plugins/modules/homebrew_services.py:10:0: import-before-documentation: Import found before documentation variables. All imports must appear below DOCUMENTATION/EXAMPLES/RETURN.
The test ansible-test sanity --test pylint
[explain] failed with 1 error:
plugins/module_utils/homebrew.py:138:0: trailing-whitespace: Trailing whitespace
The test ansible-test sanity --test pylint
[explain] failed with 1 error:
plugins/module_utils/homebrew.py:138:0: trailing-whitespace: Trailing whitespace
The test ansible-test sanity --test validate-modules
[explain] failed with 7 errors:
plugins/modules/homebrew_services.py:0:0: attributes-check-mode: The module does declare support for check mode, but the check_mode attribute's support value is 'None'
plugins/modules/homebrew_services.py:0:0: doc-default-does-not-match-spec: Argument 'state' in argument_spec defines default as (None) but documentation defines default as ('present')
plugins/modules/homebrew_services.py:0:0: doc-required-mismatch: Argument 'name' in argument_spec is required, but is not documented as being required
plugins/modules/homebrew_services.py:0:0: doc-required-mismatch: Argument 'state' in argument_spec is required, but is not documented as being required
plugins/modules/homebrew_services.py:0:0: invalid-documentation: DOCUMENTATION.attributes.check_mode.support: required key not provided @ data['attributes']['check_mode']['support']. Got None
plugins/modules/homebrew_services.py:0:0: invalid-documentation: DOCUMENTATION.attributes.diff_mode.support: required key not provided @ data['attributes']['diff_mode']['support']. Got None
plugins/modules/homebrew_services.py:10:0: import-before-documentation: Import found before documentation variables. All imports must appear below DOCUMENTATION/EXAMPLES/RETURN.
The test ansible-test sanity --test pylint
[explain] failed with 1 error:
plugins/module_utils/homebrew.py:138:0: trailing-whitespace: Trailing whitespace
The test ansible-test sanity --test validate-modules
[explain] failed with 7 errors:
plugins/modules/homebrew_services.py:0:0: attributes-check-mode: The module does declare support for check mode, but the check_mode attribute's support value is 'None'
plugins/modules/homebrew_services.py:0:0: doc-default-does-not-match-spec: Argument 'state' in argument_spec defines default as (None) but documentation defines default as ('present')
plugins/modules/homebrew_services.py:0:0: doc-required-mismatch: Argument 'name' in argument_spec is required, but is not documented as being required
plugins/modules/homebrew_services.py:0:0: doc-required-mismatch: Argument 'state' in argument_spec is required, but is not documented as being required
plugins/modules/homebrew_services.py:0:0: invalid-documentation: DOCUMENTATION.attributes.check_mode.support: required key not provided @ data['attributes']['check_mode']['support']. Got None
plugins/modules/homebrew_services.py:0:0: invalid-documentation: DOCUMENTATION.attributes.diff_mode.support: required key not provided @ data['attributes']['diff_mode']['support']. Got None
plugins/modules/homebrew_services.py:10:0: import-before-documentation: Import found before documentation variables. All imports must appear below DOCUMENTATION/EXAMPLES/RETURN.
The test botmeta
failed with 2 errors:
.github/BOTMETA.yml:0:0: Author kitizz not mentioned as active or inactive maintainer for plugins/modules/homebrew_services.py (mentioned are: )
.github/BOTMETA.yml:0:0: No (active or inactive) maintainer mentioned for plugins/modules/homebrew_services.py
The test ansible-test sanity --test compile --python 2.7
[explain] failed with 2 errors:
plugins/module_utils/homebrew.py:118:29: SyntaxError: def parse_brew_path(module) -> str:
plugins/modules/homebrew_services.py:156:83: SyntaxError: f"Running: {state.running}, Changed: {state.running}, PID: {state.pid}"
The test ansible-test sanity --test import --python 2.7
[explain] failed with 4 errors:
plugins/module_utils/homebrew.py:118:29: traceback: SyntaxError: invalid syntax
plugins/modules/homebrew.py:184:0: traceback: SyntaxError: invalid syntax (at plugins/module_utils/homebrew.py:118:29)
plugins/modules/homebrew_cask.py:161:0: traceback: SyntaxError: invalid syntax (at plugins/module_utils/homebrew.py:118:29)
plugins/modules/homebrew_services.py:156:83: traceback: SyntaxError: invalid syntax
The test ansible-test sanity --test compile --python 2.7
[explain] failed with 2 errors:
plugins/module_utils/homebrew.py:118:29: SyntaxError: def parse_brew_path(module) -> str:
plugins/modules/homebrew_services.py:156:83: SyntaxError: f"Running: {state.running}, Changed: {state.running}, PID: {state.pid}"
The test ansible-test sanity --test compile --python 3.5
[explain] failed with 1 error:
plugins/modules/homebrew_services.py:156:83: SyntaxError: f"Running: {state.running}, Changed: {state.running}, PID: {state.pid}"
The test ansible-test sanity --test import --python 2.7
[explain] failed with 4 errors:
plugins/module_utils/homebrew.py:118:29: traceback: SyntaxError: invalid syntax
plugins/modules/homebrew.py:184:0: traceback: SyntaxError: invalid syntax (at plugins/module_utils/homebrew.py:118:29)
plugins/modules/homebrew_cask.py:161:0: traceback: SyntaxError: invalid syntax (at plugins/module_utils/homebrew.py:118:29)
plugins/modules/homebrew_services.py:156:83: traceback: SyntaxError: invalid syntax
The test ansible-test sanity --test import --python 3.5
[explain] failed with 1 error:
plugins/modules/homebrew_services.py:156:83: traceback: SyntaxError: invalid syntax
Hi @felixfontein, who should I put as the author for this? I'm happy to be a maintainer if that's expected of me. Otherwise if existing authors for the homebrew.py package makes more sense, happy to do that do.
Hi @felixfontein, who should I put as the author for this? I'm happy to be a maintainer if that's expected of me. Otherwise if existing authors for the homebrew.py package makes more sense, happy to do that do.
Since you created it, I would put yourself in there :) Depending on how much you copied over from the existing module, adding the author(s) from the original module also makes sense. (If you used code from existing modules, it's best to copy over their copyright lines so it's clear that you didn't create everything yourself. Adding the authors of the other module as authors is optional, but the copyright lines are not.)
If you add a new module or plugin we expect you to at least maintain it for some time, so you'd also need to add yourself to BOTMETA (see https://github.com/ansible-collections/community.general/blob/main/CONTRIBUTING.md#creating-new-modules-or-plugins for details).
Since you created it, I would put yourself in there :) ...
Yup! Makes sense. Only too happy to.
Hmmm, not sure what to make of the following error:
07:34 fatal: [testhost]: FAILED! => {
07:34 "changed": false,
07:34 "module_stderr": "shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied\njob-working-directory: error retrieving current directory: getcwd: cannot access parent directories: Permission denied\nTraceback (most recent call last):\n File \"<stdin>\", line 133, in <module>\n File \"<stdin>\", line 125, in _ansiballz_main\n File \"<stdin>\", line 73, in invoke_module\n File \"<frozen runpy>\", line 226, in run_module\n File \"<frozen runpy>\", line 98, in _run_module_code\n File \"<frozen runpy>\", line 88, in _run_code\n File \"/tmp/ansible_community.general.homebrew_services_payload_eupguqp0/ansible_community.general.homebrew_services_payload.zip/ansible_collections/community/general/plugins/modules/homebrew_services.py\", line 279, in <module>\n File \"/tmp/ansible_community.general.homebrew_services_payload_eupguqp0/ansible_community.general.homebrew_services_payload.zip/ansible_collections/community/general/plugins/modules/homebrew_services.py\", line 264, in main\n File \"/tmp/ansible_community.general.homebrew_services_payload_eupguqp0/ansible_community.general.homebrew_services_payload.zip/ansible_collections/community/general/plugins/modules/homebrew_services.py\", line 183, in start_service\n File \"/tmp/ansible_community.general.homebrew_services_payload_eupguqp0/ansible_community.general.homebrew_services_payload.zip/ansible_collections/community/general/plugins/modules/homebrew_services.py\", line 150, in _brew_service_state\n File \"/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/__init__.py\", line 346, in loads\n return _default_decoder.decode(s)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py\", line 337, in decode\n obj, end = self.raw_decode(s, idx=_w(s, 0).end())\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py\", line 355, in raw_decode\n raise JSONDecodeError(\"Expecting value\", s, err.value) from None\njson.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)\n",
07:34 "module_stdout": "",
07:34 "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
07:34 "rc": 1
07:34 }
There seem to be multiple errors. One about getcwd permissions and one error parsing the JSON output of the services call. But I can't reproduce those on my system. Is there some extra stuff I need to set up for permissions in the Mac tests for CI?
While it doesn't show where the messages on stderr come from, it shows why stdout isn't JSON: it starts with two non-JSON lines
Hide this warning by setting HOMEBREW_SERVICES_NO_DOMAIN_WARNING.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
(And seriously, dumping stuff on stdout when the user is explicitly asking for JSON is a really bad idea.)
It also shows that you should use better error handling and not simply assume that stdout is JSON :)
Good call on the error handling. I added a try-except around json.loads
and in the tests I disabled the warnings. They seem not to affect the services. I'm assuming the getcwd
issue is from quirks in the test env and directory permissions?
Thanks for the review ♥️ Definitely a few holes in my very fresh understanding of the Ansible workings!
It is a bit over-complicated.
I guess it depends on the definition of complicated (sorry to get semantic). I agree that the type-checking logic adds some complication, but I really appreciate good static type checking. Though, if that's at odds with other goals of this project I'm happy to nix it.
Now that a few blocks of logic have been condensed using check_rc, I'm struggling to find ways to make it less over-complicated. The main logic is four core functions + two helper functions that exist in <100 lines of code. They each have a consistent cadence to them to help with maintainability. And I've done my best to highlight the entrypoints to the logic and help other code adventurers when diving in. And I guess I'm not a huge fan of "code golf" in production code.
I'm absolutely (and obviously) a total newbie when it comes to Ansible, but I feel fairly confident in my choice of logical flow. But that doesn't mean I'm not super open to specific suggestions to improve it! Always an opportunity to get better.
The test ansible-test sanity --test validate-modules
[explain] failed with 4 errors:
plugins/modules/homebrew_services.py:0:0: doc-default-does-not-match-spec: Argument 'path' in argument_spec defines default as (['/usr/local/bin', '/opt/homebrew/bin', '/home/linuxbrew/.linuxbrew/bin']) but documentation defines default as (['/usr/local/bin:/opt/homebrew/bin:/home/linuxbrew/.linuxbrew/bin'])
plugins/modules/homebrew_services.py:0:0: doc-type-does-not-match-spec: Argument 'path' in argument_spec defines type as 'list' but documentation defines type as 'path'
plugins/modules/homebrew_services.py:0:0: invalid-ansiblemodule-schema: AnsibleModule.argument_spec.path.element: extra keys not allowed @ data['argument_spec']['path']['element']. Got 'path'
plugins/modules/homebrew_services.py:0:0: parameter-list-no-elements: Argument 'path' in argument_spec defines type as list but elements is not defined
The test ansible-test sanity --test validate-modules
[explain] failed with 4 errors:
plugins/modules/homebrew_services.py:0:0: doc-default-does-not-match-spec: Argument 'path' in argument_spec defines default as (['/usr/local/bin', '/opt/homebrew/bin', '/home/linuxbrew/.linuxbrew/bin']) but documentation defines default as (['/usr/local/bin:/opt/homebrew/bin:/home/linuxbrew/.linuxbrew/bin'])
plugins/modules/homebrew_services.py:0:0: doc-type-does-not-match-spec: Argument 'path' in argument_spec defines type as 'list' but documentation defines type as 'path'
plugins/modules/homebrew_services.py:0:0: invalid-ansiblemodule-schema: AnsibleModule.argument_spec.path.element: extra keys not allowed @ data['argument_spec']['path']['element']. Got 'path'
plugins/modules/homebrew_services.py:0:0: parameter-list-no-elements: Argument 'path' in argument_spec defines type as list but elements is not defined
The test ansible-test sanity --test validate-modules
[explain] failed with 4 errors:
plugins/modules/homebrew_services.py:0:0: doc-default-does-not-match-spec: Argument 'path' in argument_spec defines default as (['/usr/local/bin', '/opt/homebrew/bin', '/home/linuxbrew/.linuxbrew/bin']) but documentation defines default as (['/usr/local/bin:/opt/homebrew/bin:/home/linuxbrew/.linuxbrew/bin'])
plugins/modules/homebrew_services.py:0:0: doc-type-does-not-match-spec: Argument 'path' in argument_spec defines type as 'list' but documentation defines type as 'path'
plugins/modules/homebrew_services.py:0:0: invalid-ansiblemodule-schema: AnsibleModule.argument_spec.path.element: extra keys not allowed @ data['argument_spec']['path']['element']. Got 'path'
plugins/modules/homebrew_services.py:0:0: parameter-list-no-elements: Argument 'path' in argument_spec defines type as list but elements is not defined
The test ansible-test sanity --test validate-modules
[explain] failed with 4 errors:
plugins/modules/homebrew_services.py:0:0: doc-default-does-not-match-spec: Argument 'path' in argument_spec defines default as (['/usr/local/bin', '/opt/homebrew/bin', '/home/linuxbrew/.linuxbrew/bin']) but documentation defines default as (['/usr/local/bin:/opt/homebrew/bin:/home/linuxbrew/.linuxbrew/bin'])
plugins/modules/homebrew_services.py:0:0: doc-type-does-not-match-spec: Argument 'path' in argument_spec defines type as 'list' but documentation defines type as 'path'
plugins/modules/homebrew_services.py:0:0: invalid-ansiblemodule-schema: AnsibleModule.argument_spec.path.element: extra keys not allowed @ data['argument_spec']['path']['element']. Got 'path'
plugins/modules/homebrew_services.py:0:0: parameter-list-no-elements: Argument 'path' in argument_spec defines type as list but elements is not defined
Thanks for the review ♥️ Definitely a few holes in my very fresh understanding of the Ansible workings!
It is a bit over-complicated.
I guess it depends on the definition of complicated (sorry to get semantic). I agree that the type-checking logic adds some complication, but I really appreciate good static type checking. Though, if that's at odds with other goals of this project I'm happy to nix it.
Absolutely. Maybe that was not the best choice of words from my side. I will use the English-as-second-language-at-10pm card to evade that one ;-).
It just felt more elaborated than needed, in great extent because of the typing, but no need to go to lengths to remove that, it is just personal preference.
Now that a few blocks of logic have been condensed using check_rc, I'm struggling to find ways to make it less over-complicated. The main logic is four core functions + two helper functions that exist in <100 lines of code. They each have a consistent cadence to them to help with maintainability. And I've done my best to highlight the entrypoints to the logic and help other code adventurers when diving in. And I guess I'm not a huge fan of "code golf" in production code.
I'm absolutely (and obviously) a total newbie when it comes to Ansible, but I feel fairly confident in my choice of logical flow. But that doesn't mean I'm not super open to specific suggestions to improve it! Always an opportunity to get better.
We have all been there once, and we still learn more stuff to this day. Thanks for your contribution :-)
Truly, I'm stoked to see such thorough reviews in open source projects. And I know that taking the time to educate fresh folks can be a serious undertaking. So thank you!
If nobody objects, I'll merge this next week.
Backport to stable-9: 💚 backport PR created
✅ Backport PR branch: patchback/backports/stable-9/2963004991dcbd8d979ef69a146c5bbbb70c52e6/pr-8329
Backported as https://github.com/ansible-collections/community.general/pull/8697
🤖 @patchback I'm built with octomachinery and my source is open — https://github.com/sanitizers/patchback-github-app.
@kitizz thanks for your contribution! @russoz thanks for reviewing!