Krikri::SystemdUnitFound
Ansible's own systemd module decides ONCE, before it acts on the
unit, whether that unit exists at all (found), and then refuses to
enable/disable or start/stop something it could not find - see
the Ansible module's fail_if_missing, called as
fail_if_missing(module, found, unit, msg='host') at the top of both the
enabled: and state: blocks of systemd_service.py.
Its is_systemd test is deliberately narrow: systemctl show <unit> must
have exited 0 AND printed a LoadState property AND that LoadState must
not be "not-found". A unit that is masked still has a LoadState of
"masked" and therefore counts as FOUND - masking is a real operation
real performs on a not-yet-installed unit, so "not installed" must not
be confused with "installed but hidden". is_initd is a separate,
equally sufficient signal: Ansible's sysv_exists() just checks for the
init script under /etc/init.d.
Factored into its own file (like SystemdEnabledState next door) so a spec can require the decision logic directly without triggering plugins/systemd.cr's bottom-of-file STDIN entry point.
Class methods
systemctl show <unit> (the same probe Ansible runs, reused here rather
than a second round trip) plus the SysV init-script presence Ansible's
sysv_exists() checks. Ansible's remaining fallbacks for a show that
exits non-zero (the "Failed to parse bus message" workaround, then
is-enabled/list-unit-files) are not replicated: nothing on this path
has ever consulted them, so a show that fails for anything other
than the no-bus case leaves the unit reported as missing.
systemctl show prints one KEY=VALUE line per unit property; real
parses the whole thing into result['status'] and reads LoadState out
of that dict. Only the first LoadState line is looked at, matching the
dict-building parse (a later duplicate key would overwrite the earlier
one, but systemctl never emits one).