-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new systemd_info module #9764
Conversation
I have corrected the result object because previously it was added directly to the like: results.units['sshd-keygen.target'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi @NomakCooper
Thanks for your PR! I've made an initial review.
Thanks for your review comments. I've made some changes based on your suggestions:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @NomakCooper thanks for the adjustments. I have a couple of additional comments, but I re iewed from the phone so I may have easily made some mistake. Take it with a grain of salt.
I have made some changes based on the suggestions.
|
I think you misunderstood that documenation. You only need it if you really need a shell. In 99% of all cases you don't need a shell. Using a shell is quite dangerous in general, so if there is no absolute need to use it, it should not be used. Regarding the systemd docs fragment: I don't think that makes sense here. |
@felixfontein @russoz Thanks for the help and suggestions. Regarding Latest changes:
|
|
Do you have any other suggestions, or does it look good to you? 😊 |
I have some more docs suggestions: diff --git a/plugins/modules/systemd_info.py b/plugins/modules/systemd_info.py
index f550b813d..a5e03a228 100644
--- a/plugins/modules/systemd_info.py
+++ b/plugins/modules/systemd_info.py
@@ -16,8 +16,8 @@ description:
- This module gathers info about systemd units (services, targets, sockets, mount).
- It runs C(systemctl list-units) (or processes selected units) and collects properties
for each unit using C(systemctl show).
- - Even if a unit has a V(loadstate) of V(not-found) or V(masked), it is returned,
- but only with the minimal properties (V(name), V(loadstate), V(activestate), V(substate)).
+ - Even if a unit has a RV(units[].loadstate) of V(not-found) or V(masked), it is returned,
+ but only with the minimal properties (RV(units[].name), RV(units[].loadstate), RV(units[].activestate), RV(units[].substate)).
- When O(unitname) and O(extra_properties) are used, the module first checks if the unit exists,
then check if properties exist. If not, the module fails.
version_added: "10.4.0"
@@ -66,7 +66,9 @@ EXAMPLES = r'''
RETURN = r'''
units:
- description: Dictionary of systemd unit info keyed by unit name.
+ description:
+ - Dictionary of systemd unit info keyed by unit name.
+ - Additional fields will be returned depending on the value of O(extra_properties).
returned: success
type: dict
elements: dict
@@ -79,24 +81,37 @@ units:
loadstate:
description:
- The state of the unit's configuration load.
- - Either V(loaded), V(not-found), V(masked).
returned: always
type: str
sample: loaded
+ choices:
+ - loaded
+ - not-found
+ - masked
activestate:
description:
- The current active state of the unit.
- - Either V(active), V(inactive), V(failed).
returned: always
type: str
sample: active
+ choices:
+ - active
+ - inactive
+ - failed
substate:
description:
- The detailed sub state of the unit.
- - Either V(running), V(dead), V(exited), V(failed), V(listening), V(active), V(mounted).
returned: always
type: str
sample: running
+ choices:
+ - running
+ - dead
+ - exited
+ - failed
+ - listening
+ - active
+ - mounted
fragmentpath:
description: Path to the unit's fragment file.
returned: always except for C(.mount) units.
@@ -105,17 +120,21 @@ units:
unitfilepreset:
description:
- The preset configuration state for the unit file.
- - Either V(enabled), V(disabled).
returned: always except for C(.mount) units.
type: str
sample: disabled
+ choices:
+ - enabled
+ - disabled
unitfilestate:
description:
- The actual configuration state for the unit file.
- - Either V(enabled), V(disabled).
returned: always except for C(.mount) units.
type: str
sample: enabled
+ choices:
+ - enabled
+ - disabled
mainpid:
description: PID of the main process of the unit.
returned: only for C(.service) units. Besides that, I think it's good. |
Thanks @felixfontein
For example, I included only the most common ones in the documentation since knowing all the possible values is quite difficult. |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Backport to stable-10: 💚 backport PR created✅ Backport PR branch: Backported as #9800 🤖 @patchback |
* add systemd_info module * fix object results * apply review changes * apply module change and add doc_fragments * removed use_unsafe_shell and doc_fragments/systemd * fix unitname description doc * fixed doc, replaced systemctl show syntax, added base prop result doc * fix documentation * fix RV values in description * fix RV() description values * add get_bin_path try/fail and remove list() * fix doc, removed try block * add Archlinux in integration test (cherry picked from commit 8425464)
@NomakCooper thanks for your contribution! |
…9800) Add new systemd_info module (#9764) * add systemd_info module * fix object results * apply review changes * apply module change and add doc_fragments * removed use_unsafe_shell and doc_fragments/systemd * fix unitname description doc * fixed doc, replaced systemctl show syntax, added base prop result doc * fix documentation * fix RV values in description * fix RV() description values * add get_bin_path try/fail and remove list() * fix doc, removed try block * add Archlinux in integration test (cherry picked from commit 8425464) Co-authored-by: Nocchia <133043574+NomakCooper@users.noreply.github.com>
SUMMARY
This PR adds a new module,
systemd_info
, to thecommunity.general
collection.I decided to develop the
systemd_info
module to give all Ansible users the ability to gather detailed information about systemd units (service
,target
,socket
,mount
).The module gathers detailed
systemd
unit (service
,target
,socket
,mount
) info using thesystemctl
command.It supports both global and select modes, and includes the ability to collect additional properties as specified by the user.
Key Features
Global and Select Modes:
systemctl
.unitname
parameter. The module first verifies unit existence and, if not found, module fail.Customizable Properties:
extra_properties
parameter allows users to request extra unit properties beyond the defaults.Detailed Return Values:
register
function to access the return values.Usage Examples
Return Examples
ISSUE TYPE
COMPONENT NAME
systemd_info
ADDITIONAL INFORMATION
Base Properties table
ALL possibile unit properties can be collected by user using
unitname
/extra_properties
optionsIn this PR:
systemd_info
module inplugins/modules/systemd_info.py
.tests/integration/targets/systemd_info/
..github/BOTMETA.yml
.Ansible sanity and integration tests were successfully run locally using Docker.