From 91a1643c84dab8820e06d542c8f0dfd236e823e5 Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Thu, 14 Nov 2024 16:57:25 +0100 Subject: [PATCH] feat: use systemctl json output to build up fact for internal services --- lib/facter/systemd.rb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/facter/systemd.rb b/lib/facter/systemd.rb index d6a2db3a..3c165db7 100644 --- a/lib/facter/systemd.rb +++ b/lib/facter/systemd.rb @@ -50,14 +50,10 @@ end Facter.add(:systemd_internal_services) do + require 'json' confine systemd: true setcode do - command_output = Facter::Util::Resolution.exec( - 'systemctl list-unit-files --no-legend --no-pager "systemd-*" -t service --state=enabled,disabled,enabled-runtime,indirect' - ) - lines = command_output.lines.lazy.map { |line| line.split(%r{\s+}) } - lines.each_with_object({}) do |(service, status, *), result| - result[service] = status - end + command_output = Facter::Util::Resolution.exec('systemctl list-unit-files "systemd-*" -t service --state=enabled,disabled,enabled-runtime,indirect -o json') + JSON.parse(command_output).to_h { |service| [service['unit_file'], service['state']] } end end