Skip to content

Commit

Permalink
Better handling output of systemctl --version
Browse files Browse the repository at this point in the history
  • Loading branch information
vzhestkov committed Aug 28, 2024
1 parent 246d066 commit 5d905c8
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions salt/grains/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2518,10 +2518,24 @@ def _systemd():
"""
Return the systemd grain
"""
systemd_info = __salt__["cmd.run"]("systemctl --version").splitlines()
systemd_output = __salt__["cmd.run_all"]("systemctl --version")
systemd_version = "UNDEFINED"
systemd_features = ""
if systemd_output.get("retcode") == 0:
systemd_info = systemd_output.get("stdout", "").splitlines()
try:
if systemd_info[0].startswith("systemd "):
systemd_version = systemd_info[0].split()[1]
systemd_features = systemd_info[1]
except IndexError:
pass
if systemd_version == "UNDEFINED" or systemd_features == "":
log.error(
"Unexpected output returned by `systemctl --version`: %s", systemd_output
)
return {
"version": systemd_info[0].split()[1],
"features": systemd_info[1],
"version": systemd_version,
"features": systemd_features,
}


Expand Down

0 comments on commit 5d905c8

Please sign in to comment.