This commit is contained in:
Thomas Sjögren 2026-05-27 22:07:58 -05:00 committed by GitHub
commit eba5e573eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 5 deletions

View file

@ -0,0 +1,3 @@
---
bugfixes:
- facts - add systemd full_version and ensure version is integer

View file

@ -18,6 +18,8 @@
from __future__ import annotations
import typing as t
import contextlib
from ansible.module_utils.facts.collector import BaseFactCollector
from ansible.module_utils.facts.system.service_mgr import ServiceMgrFactCollector
@ -39,9 +41,16 @@ class SystemdFactCollector(BaseFactCollector):
if rc != 0:
return systemd_facts
systemd_facts["systemd"] = {
"features": str(stdout.split("\n")[1]),
"version": int(stdout.split(" ")[1]),
}
systemd_version = stdout.split(" ")[1]
systemd_facts["systemd"] = {}
systemd_facts["systemd"]["features"] = stdout.split("\n")[1]
systemd_facts["systemd"]["full_version"] = str(
stdout.split(" ")[2].split(")")[0][1:],
)
with contextlib.suppress(ValueError):
systemd_version = int(systemd_version)
systemd_facts["systemd"]["version"] = systemd_version
return systemd_facts

View file

@ -1,5 +1,5 @@
---
- name: Show Gathered Facts
- name: Show systemd facts
ansible.builtin.debug:
msg: "{{ ansible_systemd }}"
@ -9,3 +9,5 @@
- ansible_systemd.version | int > 0
- ansible_systemd.version is match('^[1-9][0-9][0-9]$')
- ansible_systemd.features | regex_search('(\\+|-)(PAM|AUDIT)') is not none
- ansible_systemd.full_version is match('^[1-9][0-9][0-9](.|-|~)|^[1-9][0-9][0-9]$')
- (ansible_systemd.full_version | type_debug == 'AnsibleUnsafeText' or ansible_systemd.full_version | type_debug == 'str')